2012-02-16 40 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> 

,这是有帮助的!