Starting from Hibernate 4.3.0 it is unable to load collections mapped as follows:
{code:java} @ManyToMany @JoinTable( name = "FirstEntity_SecondEntity", joinColumns = @JoinColumn(name = "firstEntity_uuid"), inverseJoinColumns = @JoinColumn(name = "secondEntity_guid", referencedColumnName = "guid")) @Where(clause = "isLast = 1") private Set<SecondEntity> secondEntities; {code} Key part of this is _SecondEntity.guid_ not being an _@Id_. While loading this collection Hibernate issues additional query that looks like this:
{code:sql} SELECT secondenti0_.uuid AS uuid1_2_0_, secondenti0_.guid AS guid2_2_0_, secondenti0_.isLast AS isLast3_2_0_ FROM SecondEntity secondenti0_ WHERE secondenti0_.guid = ? {code}
For some reason this query neither contains proper entity ID nor condition from _@Where_ annotation thus it produces _HibernateException: More than one row with the given identifier was found_.
I`m inculding complete example that reproduces this behaviour. Just setup your DB connection in _pom.xml_ and execute _script.sql_ to create appropriate schema/data.
P.S. Issue seems to be exactly the same with _@OneToMany_ instead of _@ManyToMany_. |
|