0
基本上我有3個表格:COUNTRY,STATE和CITY。JPA Hibernate嵌套對象
在Country.java:
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "COUNTRY_ID")
private List<State> state = new Vector<State>();
在State.java
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "STATE_ID")
private List<City> city = new Vector<City>();
JPA查詢看起來像:
caEntityManager.createQuery("SELECT C FROM COUNTRY C
JOIN fetch C.STATE S JOIN fetch S.CITY").getResultList();
當我嘗試執行查詢我得到:
org.hibernate.loader.MultipleBagFetchException: cannot simultaneously fetch multiple bags
我確定我的查詢是錯誤的,我是新手,請指定我正確的方向。我
謝謝!
順便說一句,我越來越org.hibernate.loader.MultipleBagFetchException:不能同時從上面的代碼中取多個行李。 – topcan5
爲什麼使用收藏列表? –