2012-02-16 81 views
0

我有一個代碼Hibernate如何調用sequance生成器?

getEntityManager().persist(country.getCity().getClinic().getPatient()); 

,看看接下來SQL日誌

Hibernate: 
select 
    next value for patient_seq 
from 
    dual_patient_seq 
Hibernate: 
    select 
     next value for clinic_seq 
    from 
     dual_lclinic_seq 
Hibernate: 
    select 
     next value for city_seq 
    from 
     dual_city_seq 

但sequance爲 '國家' 不產生。所有的XML都是好的。汗是問題嗎? 謝謝。

+1

有關實體,特別是關係的更多信息?是否有級聯等定義?可能'國家'已被堅持? – Thomas 2012-02-16 11:48:10

+0

序列通常在實體類/ hbm xml中定義,驗證序列生成器是否爲國家定義。 – Rocky 2012-02-16 11:48:17

回答

0

Thx,Thomas!問題出現在「級聯」中。我改變City.hbm.xml從

<set name="countrysPersistent" lazy="true" inverse="true" > 
    <key column="country" /> 
     <one-to-many class="Country" /> 
     </set> 

<set name="countrysPersistent" lazy="true" inverse="true" cascade="all"> 
    <key column="country" /> 
     <one-to-many class="Country" /> 
     </set> 

,這是有幫助的!

相關問題