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!

Ean V
  • 5,091
  • 5
  • 31
  • 39
topcan5
  • 1,511
  • 8
  • 30
  • 54

1 Answers1

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.

Community
  • 1
  • 1
Ean V
  • 5,091
  • 5
  • 31
  • 39