0

I have a one-to-many relationship between two entities, the relevant parts look like this:

The "one-part" (Cart):

@OneToMany(mappedBy="cart", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private List<Item> items;

The "many-part" (Item):

@ManyToOne
private Cart cart;

This works as long as I avoid to pass a FetchType to @OneToMany. When adding a FetchType (as shown above) I get a PersistenceException (not very helpful):

[PersistenceUnit: defaultPersistenceUnit] Unable to build EntityManagerFactory

There are some other entities in my code having one-to-many-relationships that look exactly like the one above and do not procuce this exception when passing the FetchType. Why is that? I'm using Hibernate.

edit:

In case it is important: the Cart-Entity is the many-part whereas the Item-Entity is the one-part of other relationships not shown above.

edit2:

Stacktrace:

PersistenceException: [PersistenceUnit: defaultPersistenceUnit] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915) ~[hibernate-entitymanager-3.6.9.Final.jar:3.6.9.Final]
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:57) ~[hibernate-entitymanager-.6.9.Final.jar:3.6.9.Final]
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63) ~[hibernate-jpa-2.0-api.jar:1.0.1.Final]
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47) ~[hibernate-jpa-2.0-api.jar:1.0.1.Final]
at play.db.jpa.JPAPlugin.onStart(JPAPlugin.java:35) ~[play-java-jpa_2.10.jar:2.2.1]
at play.api.Play$$anonfun$start$1$$anonfun$apply$mcV$sp$1.apply(Play.scala:88) ~[play_2.10.jar:2.2.1] Caused by: org.hibernate.loader.MultipleBagFetchException: cannot simultaneously fetch multiple bags
at org.hibernate.loader.BasicLoader.postInstantiate(BasicLoader.java:94) ~[hibernate-core-3.6.9.Final.jar:3.6.9.Final]
at org.hibernate.loader.entity.EntityLoader.<init>(EntityLoader.java:119) ~[hibernate-core-3.6.9.Final.jar:3.6.9.Final]
at org.hibernate.loader.entity.EntityLoader.<init>(EntityLoader.java:71) ~[hibernate-core-3.6.9.Final.jar:3.6.9.Final]
at org.hibernate.loader.entity.EntityLoader.<init>(EntityLoader.java:54) ~[hibernate-core-3.6.9.Final.jar:3.6.9.Final]
at org.hibernate.loader.entity.BatchingEntityLoader.createBatchingEntityLoader(BatchingEntityLoader.java:133) ~[hibernate-core-.6.9.Final.jar:3.6.9.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.createEntityLoader(AbstractEntityPersister.java:1914) ~[hibernate-core-3.6.9.Final.jar:3.6.9.Final]
3
  • although the exception really seems to say nothing, it always help us when you post the stacktrace here
    – Leo
    Feb 21, 2014 at 23:10
  • True, added the stacktrace
    – alapeno
    Feb 21, 2014 at 23:22
  • thanks. You see, now we have something new here. Is this link useful? stackoverflow.com/questions/4334970/…
    – Leo
    Feb 21, 2014 at 23:25

1 Answer 1

0

For me it seems you have another collection being eagerly loaded in your entity. Consider changing one of them to fetch=FetchType.LAZY.

If not possible, remove the fetch=FetchType.EAGER from your @OneToMany relation and annotate it with @LazyCollection(LazyCollectionOption.FALSE)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.