]
Emmanuel Bernard resolved HHH-3164.
-----------------------------------
Resolution: Fixed
Fix Version/s: 3.5
Fixed. Thanks
"id in ..." with EmbeddedId and criteria API
--------------------------------------------
Key: HHH-3164
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3164
Project: Hibernate Core
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
Fix For: 3.5
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: