Can't get an SQL working with entityManager

To update our apps for Confluence 8 & Hibernate 2 removal, we need to execute an SQL on migration tables. I am doing:

Query query = entityManager.createQuery("SELECT " + ASSESSMENT_STATUS_COLUMN +
" FROM " + MIG_APP_ASSESSMENT_INFO_TABLE +
" WHERE " + APP_KEY_COLUMN + “='” + appKey + “'”);

But I get:

java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: MIG_APP_ASSESSMENT_INFO is not mapped [SELECT assessmentstatus FROM MIG_APP_ASSESSMENT_INFO WHERE appkey=‘MY_APPKEY’]

Can you provide a working example for this?
Thanks in advance!

1 Like

I’m having a similar issue trying to reference an Active Objects table with the EntityManager referenced from the Hibernate 2 Removal Guide.

@hugo Did you ever figure out what was going wrong with your attempts?

Hi @hugo @kashev

try to use createNativeQuery

entityManagerProvider.getEntityManager().createNativeQuery("select * from table");

Cheers
Adam

@adam.labus Using native queries strikes me as dangerous, given the range of databases most Atlassian host products (and thus the plugins we develop) have to support.

I did give it a go and got a different, but I think related, error.

When I try this native query (with a table that my plugin is creating)

SELECT f from AO_XXXXXX_TABLE f
    JOIN content c
    ON c.contentid = f."CONTENT_ID"
    WHERE c.spaceid = 98305;

I get this error:

javax.persistence.PersistenceException: org.hibernate.MappingException: No Dialect mapping for JDBC type: 2002

To me this is indicative of the same root issue, where Confluence-Hibernate doesn’t know about the tables that I’m adding via ActiveObjects.

I was able to get to get results that look correct with a subtle change to my query (selecting * instead of f from my table), but I’m still nervous about using native queries.

SELECT * from AO_XXXXXX_TABLE f
    JOIN content c
    ON c.contentid = f."CONTENT_ID"
    WHERE c.spaceid = 98305;