[hibernate-issues] [Hibernate-JIRA] Created: (HHH-3164) "id in ..." with EmbeddedId and criteria API

Bartosz Jablonski (JIRA) noreply at atlassian.com
Wed Mar 5 07:34:34 EST 2008


"id in ..." with EmbeddedId and criteria API
--------------------------------------------

                 Key: HHH-3164
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3164
             Project: Hibernate3
          Issue Type: Bug
          Components: query-criteria
    Affects Versions: 3.2.6
         Environment: hibrenate 3.2.5 hibernate-annotations 3.3.0, database - h2, postgresql, h2

            Reporter: Bartosz Jablonski
         Attachments: test.zip


This issue arised when I was debugging hibernate search, which wasn't retriving entities from query.

Problem is using query like 'entity.id in ...'  with criteria api and embeddedId.

Let's say that we have classes:
@Entity
public class SomeEntity implements Serializable {

    @Id
    private SomeEntityId id;
(...)
}

@Embeddable
public class SomeEntityId implements Serializable {
    private Integer id;
    private Integer version;
(...)
}

In database there are rows:
(id,version)
1,11
1,12
10,21
10,22
10,23


Now I want to retrive rows with id (1,12) and (10,23) using Criteria API:

        List ids = new ArrayList<SomeEntityId>(2);
        ids.add( new SomeEntityId(1,12) );
        ids.add( new SomeEntityId(10,23) );

        Criteria criteria = session.createCriteria( SomeEntity.class );
        Disjunction disjunction = Restrictions.disjunction();
        
        disjunction.add( Restrictions.in( "id", ids  ) );
        criteria.add( Restrictions.in( "id", ids  ) );

hibernate returns no rows, because it constructs query like this:
select this_.id as id0_0_, this_.version as version0_0_, this_.prop as prop0_0_ from SomeEntity this_ where (this_.id, this_.version) in ((1, 10), (12, 23)) 

instead of 
select * from SomeEntity where (id, version) in ((1, 12), (10, 23)) 


As example I attached maven project which is using h2 database - just run class test.App


-- 
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