[hibernate-issues] [Hibernate-JIRA] Issue Comment Edited: (HHH-5792) Unable to JOIN embedded objects in Criteria API

Thomas Pischke (JIRA) noreply at atlassian.com
Tue Jun 7 15:34:24 EDT 2011


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

Thomas Pischke edited comment on HHH-5792 at 6/7/11 2:32 PM:
-------------------------------------------------------------

Where this gets really ugly is when the embedded object in turn contains a collection of entities.  I see no way to join the collection contained in the component to the entity containing the embedded component.  This means it is not possible to query the collection in the component.  It's also not possible to specify a left join rather than an inner join in the case of querying simple properties on the embedded component.  Hopefully I'm missing the obvious or a workaround is available.  

      was (Author: tpischke2):
    Where this gets really ugly is when the embedded object in turn contains a collection of entities.  I see no way to join the collection contained in the component to the entity containing the embedded component.  This means it is not possible to query the collection in the component.  Hopefully I'm missing the obvious or a workaround is available.  
  
> Unable to JOIN embedded objects in Criteria API
> -----------------------------------------------
>
>                 Key: HHH-5792
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5792
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: entity-manager, query-criteria
>    Affects Versions: 3.6.0
>            Reporter: scLee
>            Priority: Blocker
>         Attachments: Client.java, CriteriaApiTest.java, Name.java
>
>
> Exception is thrown when trying to JOIN embedded attribute in Criteria API. E.g. having the following entity:
> {quote}
> @Entity
> public class Client implements Serializable {    
>     @Id
>     public int id;
>     @Embedded
>     public Name name;
> }
> @Embeddable
> public class Name implements Serializable {
>     @Column
>     public String firstName;
>     @Column
>     public String lastName;
> }
> {quote}
> The following code
> {quote}
>         CriteriaQuery< Client > cq = cb.createQuery( Client.class );
>         Root< Client > root = cq.from( Client.class );
>         cq.where( cb.equal( root.*join*( "name" ).get( "firstName" ), "foo" ) );
> {quote}
> throws this exception:
> {quote}
> java.lang.ClassCastException: org.hibernate.ejb.metamodel.SingularAttributeImpl cannot be cast to javax.persistence.metamodel.ManagedType
> 	at org.hibernate.ejb.criteria.path.AbstractFromImpl.locateManagedType(AbstractFromImpl.java:151)
> 	at org.hibernate.ejb.criteria.path.AbstractFromImpl.locateAttributeInternal(AbstractFromImpl.java:145)
> 	at org.hibernate.ejb.criteria.path.AbstractPathImpl.locateAttribute(AbstractPathImpl.java:216)
> 	at org.hibernate.ejb.criteria.path.AbstractFromImpl.join(AbstractFromImpl.java:449)
> 	at org.hibernate.ejb.criteria.path.AbstractFromImpl.join(AbstractFromImpl.java:433)
> 	at foo.CriteriaApiTest.embeddableInPath(CriteriaApiTest.java:45)
> {quote}

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list