Bug fix related to CriteriaQuery (JPA) when using XML mappings

Description

Hi,

I use XML mapping and wanted to implement the following query using CriteriaQuery.

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

(Actually my query is more complex than that but it was the first step.)

The first bug was that query generated the following jpql

select generatedAlias0 from null as generatedAlias0

This was because the org.hibernate.mapping.PersistentClass.jpaEntityName attribute was not set

Once I fixed it if tried to add a WHERE clause which was

cq.where(cb.equal(objRoot.get("embeddablePkId").get("embeddablePkIdAttribute"), "valueToSearch"));

which resulted into a NullPointerException because the org.hibernate.mapping.RootClass.declaredIdentifierProperty attribute was not set for simple and embeddable PK

Theses 2 attributes are well set but only when using annotation mappings because they are set via the AnnotationBinder.
In my case, with XML mapping, it calls the HbmBinder so these attributes are never set.

Here are my bug fixes, hope this help.
Cheers,

$ git diff
diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/HbmBinder.java b/hib
index dd0e14a..4cacb8e 100644
— a/hibernate-core/src/main/java/org/hibernate/cfg/HbmBinder.java
+++ b/hibernate-core/src/main/java/org/hibernate/cfg/HbmBinder.java
@@ -451,6 +451,7 @@ public final class HbmBinder {
prop.setValue( id );
bindProperty( idNode, prop, mappings, inheritedMetas );
entity.setIdentifierProperty( prop );
+ entity.setDeclaredIdentifierProperty( prop );
}

// TODO:
@@ -484,6 +485,7 @@ public final class HbmBinder {
prop.setValue( id );
bindProperty( idNode, prop, mappings, inheritedMetas );
entity.setIdentifierProperty( prop );
+ entity.setDeclaredIdentifierProperty( prop );
}

makeIdentifier( idNode, id, mappings );
@@ -564,6 +566,7 @@ public final class HbmBinder {
throw new MappingException( "Unable to determine entity
}
persistentClass.setEntityName( entityName );
+ persistentClass.setJpaEntityName( entityName );

bindPojoRepresentation( node, persistentClass, mappings, inherit
bindDom4jRepresentation( node, persistentClass, mappings, inheri
(END)

Attachments

1
  • 04 Nov 2011, 02:00 PM

Activity

BrianJuly 25, 2012 at 7:51 AM

Is this never going to be fixed in 3.6?

Strong LiuMarch 6, 2012 at 5:26 PM

thanks for the patch

Strong LiuFebruary 20, 2012 at 2:28 PM

yep, due to the lack of resource, we won't release further 3.6.x. but it is easy to get 3.6 branch source and apply the fix to it, and build a release by yourself.

Kariem HusseinFebruary 20, 2012 at 12:56 PM

Thank you for confirming that we also had this issue on 4.x/4.1 and providing a fix. If possible, please also update the affects version field on this issue.

Unfortunately, I have just seen that my pull request was closed with the notice "development work has been moved to 4.x, there is no further plan for 3.6". To my understanding, we won't see a fix for that on 3.6 although a test case and fix has been provided nearly 100 days before that (now assumed) final release 3.6.10.

Strong LiuFebruary 20, 2012 at 10:26 AM

Fixed

Details

Assignee

Reporter

Original estimate

Time tracking

No time logged1h remaining

Components

Fix versions

Priority

Created April 8, 2011 at 4:47 PM
Updated July 25, 2012 at 7:51 AM
Resolved March 6, 2012 at 5:26 PM

Flag notifications