]
Gail Badner commented on HHH-5118:
----------------------------------
This looks like a duplicate of HHH-4991. Can you try increasing max_fetch_depth and see if
that works?
Criteria not generating whole SQL (missing select, missing join)
----------------------------------------------------------------
Key: HHH-5118
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5118
Project: Hibernate Core
Issue Type: Bug
Affects Versions: 3.5.1
Reporter: ChB
Priority: Critical
I use the following code:
class X {
@ManyToMany(mappedBy = "x")
public Set<Y> getY() {
return this.y;
}
}
class Y {
@ManyToMany(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY)
@JoinTable(name = "x_to_y", joinColumns = { @JoinColumn(name = "y")
}, inverseJoinColumns = { @JoinColumn(name = "x") })
public Set<X> getX() {
return this.x;
}
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "y_to_z", joinColumns = { @JoinColumn(name = "y")
}, inverseJoinColumns = { @JoinColumn(name = "z") })
@OrderBy("name ASC")
public List<Z> getZ() {
return this.z;
}
}
class Z {
@ManyToMany(mappedBy = "z", cascade = CascadeType.ALL)
public Set<Y> getY() {
return this.y;
}
@ManyToMany(fetch = FetchType.LAZY, mappedBy = "broken")
public Set<Broken> getBroken() {
return this.broken;
}
}
class Broken {
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "z_to_broken", joinColumns = { @JoinColumn(name =
"broken") }, inverseJoinColumns = { @JoinColumn(name = "z") })
@OrderBy("name ASC")
public List<Z> getZ() {
return this.z;
}
}
And perform the following criteria query:
Criteria criteria = session.createCriteria(X.class);
Criteria criteriaY = criteria.createCriteria("y");
Criteria criteriaZ = criteriaY.createCriteria("z");
Criteria criteriaBroken = criteriaZ.createCriteria("broken");
criteriaBroken.add(Restrictions.eq("id", 1));
This results in the following SQL
select this_.id as id14_4_,
this_.* as ...,
x_to_y5_.x as x2_14_,
y1_.id as y,
y1_.id as id3_0_,
y1_.* as ...,
z9_.y as y1_3_,
z2_.id as z2_,
z2_.id as id19_3_,
z2_.* as ...,
from y this_
inner join x_to_y x_to_y5_ on this_.id=x_to_y5_.x
left outer join y y1_ on x_to_y5_.y=y1_.id
inner join y_to_z z9_ on y1_.id=z9_.y_id
left outer join z z2_ on z9_.z=z2_.id
inner join z_to_broken broken11_ on z2_.id=broken11_.z
where broken3_.id=1
There are 2 errors in the SQL which might come down to the same issue:
1.) In the select clause right before the 'from y this_' is a ',' which
shows that not all columns where put in the select clause.
2.) In the where clause a 'broken3_' is used which was never declared before.
This works fine in Hibernate 3.3.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: