jpaEntityName not set when using Hibernate mapping

Description

I'm trying to run the following query

CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<Qualifier> cq = cb.createQuery(Qualifier.class);
Root<Qualifier> qualifRoot = cq.from(Qualifier.class);
List<Qualifier> results = entityManager.createQuery(cq).getResultList();

The Qualifier class is mapped using Hibernate hbm.xml mapping (see attachement)

The entityManagerFactory is configured using a Spring class
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
...
</bean>

This Criteria query throws the exception: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: null near line 1, column 29 [select generatedAlias0 from null as generatedAlias0]

The FROM clause, which here is null, is built using the EntityType.jpaEntityName property which value comes from PersistentClass.jpaEntityName property. But this property is never set when context is loaded to build the Metamodel.
Is this property not set because the mapping is an hibernate mapping and not a JPA one ? or is it a bug ?

Attachments

1

Activity

Brett MeyerMarch 7, 2014 at 5:30 PM

Bulk closing rejected tickets in "resolved" state.

Scott BasingerJanuary 26, 2012 at 7:50 PM

After a little more testing, the setting of jpaEntityName should be done in bindRootClass, handleSubclass, handleJoinedSubclass and handleUnionSubclass by adding a line similar to this:

subclass.setJpaEntityName(subclass.getNodeName());

Then the bindSimpleID and bindCompositeId methods would have the line:

entity.setDeclaredIdentifierProperty(prop);

Then we get rid of our UnknownProperty and generatedAlias null issues. (So far).

NellyJJanuary 24, 2012 at 6:34 PM

Hi Scott,

Thank you for fixing this.
Actually you should have added 3 lines, because in HbmBinder there is 2 places where you have to fix the setting of declaredIdentifierProperty (in bindSimpleId method and also in bindCompositeId method unless theses methods have changed since my bug report)
Anyway, I suppose you can also close this bug which is related to the same problem
https://hibernate.onjira.com/browse/HHH-6100?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=44252#comment-44252
Will this bug fix be included in the next version of hibernate-core ?

Scott BasingerJanuary 24, 2012 at 5:36 PM

I added 2 lines to HBMBinder to set the declaredIdentifierProperty and the jpaEntityName. JPA over hbm files now is creating much better metadata.

if ( propertyName != null ) {
....
entity.setDeclaredIdentifierProperty(prop);
entity.setJpaEntityName(entity.getNodeName());
}

NellyJMarch 31, 2011 at 4:06 PM

After some checking it looks like the PersistenceClass.jpaEntityName is not set when using Hibernate hbm.xml mapping because this property is set in EntityBinder.bindEntity() method which is only called by AnnotationBinder.

Duplicate

Details

Assignee

Reporter

Components

Affects versions

Priority

Created March 22, 2011 at 6:01 PM
Updated March 7, 2014 at 5:30 PM
Resolved January 25, 2012 at 1:18 AM