【发布时间】:2011-09-19 05:38:16
【问题描述】:
嗨,我正在使用 MYSQL 和 Hibernate,并且有一个表 Customer,其列 customer_type 的默认值为 1,其外键在 Customer 但在 CustomerType 表中的主键找到以下代码在我的 Customer hbm 文件中,我编写了以下代码:
<many-to-one name="customerType" class="CustomerType" lazy="false">
<column name="customer_type_id" not-null="true"/>
</many-to-one>
但是该列不为空,在我的表中它的默认值为 1。我在保存我的客户对象时没有设置此对象,因为表中存在默认值但获取异常 propertyviolationexception not null 引用空值我怎么能解决这个问题以及如何在休眠中为关系设置默认值
【问题讨论】: