We changed a mapping from XDoclet/.hbm to Annotations and our initial login query no longer works. No bags are in use, but we are getting multiple Users for a userID. It is a ManyToMany with a join table.
The query is a criterion query to get all Users with userID and password equal to specified values.
Under XDoclet everythign works fine, but when mapped using Annotations, it exhibits duplicate record behavior.
Does the mapping technique (.hbm vs annotatiosn) change the query semantics? We need our existing, mature system to continue to function without re-working all the queries, so we may need to abandon our effor if they are substantially different in semantics.
We are familiar with the outer-join issues in HQL that can cause this, but did not expect that merely changing the mapping syntax would alter semantics. Can any explain what is happening?
Hibernate version:
3.2.5 core + 3.3.0 annotations
Mapping documents (I've left in the old XDoclet for reference purposes)
Code:
@Entity
@Table(name="user")
@Proxy(lazy=false)
public class User {
/**
* @hibernate.set
* name="roles"
* table="user_has_role"
* lazy="false"
* cascade="save-update"
* @hibernate.collection-key
* column="user_guid"
* @hibernate.collection-many-to-many
* class="com.app.Role"
* column="role_guid"
*/
@ManyToMany(fetch=FetchType.EAGER, targetEntity=com.app.Role.class)
@Cascade({CascadeType.SAVE_UPDATE})
@JoinTable(name="user_has_role",
joinColumns={@JoinColumn(name="user_guid")},
inverseJoinColumns={@JoinColumn(name="role_guid")})
public Set getRoles() {...
@Entity
@Table(name="role")
@Proxy(lazy=false)
public class Role {
@Basic
@Column(name="Role", nullable=false)
public String getName() {
return this.name;
}
The generated SQL (show_sql=true):Code:
[exec] 22:45:06,765 INFO [STDOUT] Hibernate:
select this_.user_guid as user1_65_1_, this_.isActive as isActive65_1_, this_.Password as Password65_1_, this_.UserID as UserID65_1_,
roles2_.user_guid as user1_3_, role3_.role_guid as role2_3_, role3_.role_guid as role1_57_0_
from
user this_
left outer join user_has_role roles2_ on this_.user_guid=roles2_.user_guid
left outer join role role3_ on roles2_.role_guid=role3_.role_guid where (this_.UserID=? and this_.Password=?)