hibernate中constrained= "true "
是不是只能用于one-to-one?我看到的很多例子在one-to-one的两边的配置文件中都有constrained= "true ",不明白这个声明的作用是什么?         请高手指教!!

解决方案 »

  1.   

    constrained(约束) (可选) 表明该类对应的表对应的数据库表,和被关联的对象所对应的数据库表之间,通过一个外键引用对主键进行约束。 这个选项影响save()和delete()在级联执行时的先后顺序以及 决定该关联能否被委托(也在schema export tool中被使用). 
      

  2.   

    constrained (optional) specifies that a foreign key constraint on the primary key of the mapped table references the table of the associated class. This option affects the order in which save() and delete() are cascaded, and determines whether the association may be proxied (it is also used by the schema export tool). 
      

  3.   

    例如:居民person和身份证Idcard之间
    <one-to-one name="idCard" constrained="true" cascade="none" />constrained="true"是指,你的person的id是由IdCard生成的。
    也就是说。IdCard要先于你的Person存在了。
    所以会先保存IDCard,然后才保存Person