Hi, i keep bumping in to the unfortunate error "org.hibernate.HibernateException: cannot simultaneously fetch multiple bags"
I have a table in which i map several entities to each other, ill try and make a "toy" example to explain ...
Mu entity beans looks similar to this (ie ... this is simplified),
Code:
@Entity
@Immutable
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
@Table(schema = "admin", name = "Access")
public class Access {
@Id
private Integer id;
@ManyToOne(targetEntity = User.class)
@JoinColumn(name = "user_id")
private User user;
@ManyToOne(targetEntity = ResourceA.class)
@JoinColumn(name = "resource_a_id")
private ResourceA resourceA;
@ManyToOne(targetEntity = ResourceB.class)
@JoinColumn(name = "resource_b_id")
private ResourceB resourceB;
}
@Entity
@Immutable
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
@Table(schema = "admin", name = "resource_a")
public class ResourceA {
@Id
private Integer id;
@Column(name = "name")
private String name;
}
@Entity
@Immutable
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
@Table(schema = "admin", name = "resource_b")
public class ResourceB {
@Id
private Integer id;
@Column(name = "name")
private String name;
}
and when i then try to load it all using a DetachedCriteria it fails with
"org.hibernate.HibernateException: cannot simultaneously fetch multiple bags"
Code:
DetachedCriteria access = DetachedCriteria.forClass(Access.class);
access.add(Restrictions.eq("user", user));
access.setProjection(Projections.distinct(Property.forName("resourceA")));
for (ResourceA resourceA: getHibernateTemplate().findByCriteria(dcAccess)) {
....
}
Hope thats enough for some one to help me :)
I have tried the eager /lazy loading.
It is a one way relations ship ... ie no connectins from resource to Access, maybe i have to inverse the relations somehow ?