[jboss-user] [EJB 3.0] - Hibernate3: Cannot simultaneously fetch multiple bags

ericmacau do-not-reply at jboss.com
Sun May 13 23:00:38 EDT 2007


Hello,

I don't know why it will raise the "Cannot simultaneously fetch multiple bags" exception, please help and teach me how can I solve the problem?


  | @Entity
  | @Table(name="EventNotes")
  | public class Notes implements Serializable {
  | 	public static final long serialVersionUID = 1L;
  | 	
  | 	protected long id;
  | 	protected User creator;
  | 	
  | 	
  | 	/**
  | 	 * @return the creator
  | 	 */
  | 	@ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
  | 	@JoinTable(name="USER_NOTES",
  | 	        joinColumns = @JoinColumn(name="NOTES_ID"),
  | 	        inverseJoinColumns = @JoinColumn(name="USER_ID")
  | 	    )
  | 	public User getCreator() {
  | 	
  | 		return this.creator;
  | 	}
  | 	
  | 	/**
  | 	 * @param creator the creator to set
  | 	 */
  | 	public void setCreator(User creator) {
  | 	
  | 		this.creator = creator;
  | 	}
  | 	
  | 	
  | 	
  | 	/**
  | 	 * @return the id
  | 	 */
  | 	@Id
  | 	@GeneratedValue(strategy = GenerationType.AUTO)
  | 	public long getId() {
  | 	
  | 		return this.id;
  | 	}
  | 	
  | 	/**
  | 	 * @param id the id to set
  | 	 */
  | 	public void setId(long id) {
  | 	
  | 		this.id = id;
  | 	}
  | 
  | 		
  | }
  | 


  | @Entity
  | @Table(name="USERS")
  | public class User implements Serializable {
  | 	public static final long serialVersionUID = 1L;
  | 
  | 	private String username;
  | 
  | 	private String password;
  | 	
  | 	
  | 	private String firstName;
  | 	private String lastName;
  | 	private String displayName;
  | 	private String gender;
  | 	
  | 
  | 	private boolean activate;
  | 	
  | 	private Collection<Role> roles = new ArrayList<Role>();
  | 	private Collection<Group> groups = new ArrayList<Group>();
  | 	
  | 
  | 
  | 
  | 	@Transient
  | 	public boolean isActivate() {
  | 		return activate;
  | 	}
  | 		
  | 	
  | 	public boolean getActivate() {
  | 		return activate;
  | 	}
  | 
  | 	public void setActivate(boolean activate) {
  | 		this.activate = activate;
  | 	}
  | 
  | 	public String getPassword() {
  | 		return password;
  | 	}
  | 
  | 	public void setPassword(String password) {
  | 		this.password = password;
  | 	}
  | 
  | 	@Id
  | 	//@GeneratedValue(strategy = GenerationType.AUTO)		
  | 	public String getUsername() {
  | 		return username;
  | 	}
  | 
  | 	public void setUsername(String username) {
  | 		this.username = username;
  | 	}
  | 	
  | 	
  | 
  | 	public String getFirstName() {
  | 		return firstName;
  | 	}
  | 
  | 	public void setFirstName(String firstName) {
  | 		this.firstName = firstName;
  | 	}
  | 
  | 	public String getLastName() {
  | 		return lastName;
  | 	}
  | 
  | 	public void setLastName(String lastName) {
  | 		this.lastName = lastName;
  | 	}
  | 	
  | 	
  | 	
  | 
  | 	public String getDisplayName() {
  | 		return displayName;
  | 	}
  | 
  | 	public void setDisplayName(String displayName) {
  | 		this.displayName = displayName;
  | 	}
  | 	
  | 	
  | 	
  | 	
  | 
  | 	public String getGender() {
  | 		return gender;
  | 	}
  | 
  | 	public void setGender(String gender) {
  | 		this.gender = gender;
  | 	}
  | 
  | 	@ManyToMany(cascade = {CascadeType.REMOVE}, 
  | 			fetch = FetchType.EAGER, 
  | 			targetEntity=Role.class)
  | 	@JoinTable(
  |         name="USER_ROLE_LINK",
  |         joinColumns={@JoinColumn(name="username")},
  |         inverseJoinColumns={@JoinColumn(name="rolename")}
  |     )
  | 	public Collection<Role> getRoles() {
  | 		return roles;
  | 	}
  | 		
  | 	
  | 	public void setRoles(Collection<Role> roles) {
  | 		this.roles = roles;
  | 	}
  | 	
  | 	@Transient
  | 	public void addRole(Role role) {
  | 		this.roles.add(role);
  | 	}
  | 
  | 
  | 	@ManyToMany(cascade = {CascadeType.REMOVE}, 
  | 			fetch = FetchType.LAZY, 
  | 			targetEntity=Group.class)
  | 	@JoinTable(
  |         name="USER_GROUP_LINK",
  |         joinColumns={@JoinColumn(name="username")},
  |         inverseJoinColumns={@JoinColumn(name="groupname")}
  |     )
  | 	public Collection<Group> getGroups() {
  | 		return groups;
  | 	}
  | 
  | 	
  | 
  | 	public void setGroups(Collection<Group> groups) {
  | 		this.groups = groups;
  | 	}
  | 
  | 	@Transient
  | 	public void addGroup(Group group) {
  | 		groups.add(group);
  | 	}
  | 	
  | 	
  | 	
  | 	@Transient
  | 	public String toString() {
  | 		StringBuffer buf = new StringBuffer();
  | 		
  | 		buf.append("=== " + username + "===\n");
  | 		buf.append(displayName + "\n");
  | 		
  | 		Iterator rs = roles.iterator();
  | 		while(rs.hasNext()) {
  | 			Role r = (Role)rs.next();
  | 			buf.append(r);
  | 		}
  | 		
  | 		Iterator gs = groups.iterator();
  | 		while(rs.hasNext()) {
  | 			Group g = (Group)rs.next();
  | 			buf.append(g);
  | 		}
  | 		
  | 		
  | 		return buf.toString();
  | 	}
  | 
  | }
  | 



  | javax.persistence.PersistenceException: org.hibernate.HibernateException: cannot simultaneously fetch multiple bags
  | 	at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:737)
  | 	at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:121)
  | 	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
  | 	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
  | 	at mo.reales.util.HibernateUtil.initFactory(HibernateUtil.java:40)
  | 	at mo.reales.util.HibernateUtil.initFactory(HibernateUtil.java:35)
  | 	at mo.reales.web.ServiceStartupListener.contextInitialized(ServiceStartupListener.java:69)
  | 	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3763)
  | 	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4211)
  | 	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:759)
  | 	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:739)
  | 	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524)
  | 	at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:904)
  | 	at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:867)
  | 	at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:474)
  | 	at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1122)
  | 	at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:310)
  | 	at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
  | 	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1021)
  | 	at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
  | 	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1013)
  | 	at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
  | 	at org.apache.catalina.core.StandardService.start(StandardService.java:450)
  | 	at org.apache.catalina.core.StandardServer.start(StandardServer.java:709)
  | 	at org.apache.catalina.startup.Catalina.start(Catalina.java:551)
  | 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  | 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  | 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  | 	at java.lang.reflect.Method.invoke(Method.java:585)
  | 	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
  | 	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:432)
  | Caused by: org.hibernate.HibernateException: cannot simultaneously fetch multiple bags
  | 	at org.hibernate.loader.BasicLoader.postInstantiate(BasicLoader.java:66)
  | 	at org.hibernate.loader.entity.EntityLoader.<init>(EntityLoader.java:75)
  | 	at org.hibernate.loader.entity.EntityLoader.<init>(EntityLoader.java:43)
  | 	at org.hibernate.loader.entity.EntityLoader.<init>(EntityLoader.java:33)
  | 	at org.hibernate.loader.entity.BatchingEntityLoader.createBatchingEntityLoader(BatchingEntityLoader.java:103)
  | 	at org.hibernate.persister.entity.AbstractEntityPersister.createEntityLoader(AbstractEntityPersister.java:1748)
  | 	at org.hibernate.persister.entity.AbstractEntityPersister.createEntityLoader(AbstractEntityPersister.java:1752)
  | 	at org.hibernate.persister.entity.AbstractEntityPersister.createLoaders(AbstractEntityPersister.java:2982)
  | 	at org.hibernate.persister.entity.AbstractEntityPersister.postInstantiate(AbstractEntityPersister.java:2975)
  | 	at org.hibernate.persister.entity.SingleTableEntityPersister.postInstantiate(SingleTableEntityPersister.java:690)
  | 	at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:290)
  | 	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
  | 	at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915)
  | 	at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:730)
  | 	... 30 more
  | 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4045327#4045327

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4045327



More information about the jboss-user mailing list