Java Mailing List Archive

http://www.gg3721.com/

Home » Hibernate Issues List »

[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-6100) Bug fix
related to CriteriaQuery (JPA) when using XML mappings

Anupam M (JIRA)

2012-01-28

Replies: Find Java Web Hosting

Author LoginPost Reply

  [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-6100?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=45286#comment-45286 ]

Gail Badner commented on HHH-6100:
----------------------------------

More fixes listed at https://hibernate.onjira.com/browse/HHH-6039?focusedCommentId=45265&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-45265 .

> Bug fix related to CriteriaQuery (JPA) when using XML mappings
> --------------------------------------------------------------
>
>           Key: HHH-6100
>           URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6100
>         Project: Hibernate ORM
>       Issue Type: Patch
>   Affects Versions: 3.6.2
>      Environment: hibernate-(core, entitymanager...)-3.6.2.Final
> hibernate-jpa-2.0-api-1.0.0.Final
> MySQL 5.1
> Spring 3.0.5.RELEASE
>        Reporter: JOUFFRE Nelly
>        Priority: Critical
>      Attachments: testmapping.zip
>
>  Original Estimate: 1h
> Remaining Estimate: 1h
>
> 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
> @@(protected) {
>                 prop.setValue( id );
>                 bindProperty( idNode, prop, mappings, inheritedMetas );
>                 entity.setIdentifierProperty( prop );
> +               entity.setDeclaredIdentifierProperty( prop );
>           }
>           // TODO:
> @@(protected) {
>                 prop.setValue( id );
>                 bindProperty( idNode, prop, mappings, inheritedMetas );
>                 entity.setIdentifierProperty( prop );
> +               entity.setDeclaredIdentifierProperty( prop );
>           }
>           makeIdentifier( idNode, id, mappings );
> @@(protected) {
>                 throw new MappingException( "Unable to determine entity
>           }
>           persistentClass.setEntityName( entityName );
> +          persistentClass.setJpaEntityName( entityName );
>           bindPojoRepresentation( node, persistentClass, mappings, inherit
>           bindDom4jRepresentation( node, persistentClass, mappings, inheri
> (END)

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

   
_______________________________________________
hibernate-issues mailing list
hibernate-issues@(protected)
https://lists.jboss.org/mailman/listinfo/hibernate-issues
©2008 gg3721.com - Jax Systems, LLC, U.S.A.