-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: How to avoid the , "Cannot load multiple bags sim..." error?
PostPosted: Mon Jan 03, 2011 10:49 am 
Newbie

Joined: Mon Jan 03, 2011 10:33 am
Posts: 1
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 ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.