0

Basically I have 3 tables: COUNTRY, STATE and CITY.

in Country.java:

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "COUNTRY_ID")
private List<State> state = new Vector<State>();

in State.java

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "STATE_ID")
private List<City> city = new Vector<City>();

JPA query looks like:

caEntityManager.createQuery("SELECT C FROM COUNTRY C 
        JOIN fetch C.STATE S JOIN fetch S.CITY").getResultList();

When I try to execute the query I get:

org.hibernate.loader.MultipleBagFetchException: cannot simultaneously fetch multiple bags

I am sure my query is wrong, i am new to this, please appoint me to the right direction. I

Thanks!

2
  • BTW, i am getting org.hibernate.loader.MultipleBagFetchException: cannot simultaneously fetch multiple bags from the code above. Commented Apr 24, 2014 at 3:48
  • Why do you use lists for the collections? Commented Apr 24, 2014 at 5:56

1 Answer 1

1

Problem is Hibernate can not fetch two bags EAGERly. The quick solution would be to change the Lists to Sets.

To read more:

Also this question suggests a couple of other solutions.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.