我正在尝试将数据库中的字段更新为空字段。我正在尝试使用hibernate来做到这一点。我可以设置对象字段像String和任何其他对象为null,但没有整数。如何使用hibernate在整数字段的数据库中设置空值?
<?xml version="1.0" encoding="UTF-8"?>
<class name="App_Users" table="app_users" schema="bidtool">
<id name="userId" type="int" column="user_id">
<generator class="assigned"/>
</id>
<property name="username" type="string">
<column name="username" length="20" not-null="true" />
</property>
<property name="password" type="string">
<column name="password" length="20" not-null="true" />
</property>
<property name="firstname" type="string">
<column name="firstname" length="20" />
</property>
<property name="lastname" type="string">
<column name="lastname" length="20" />
</property>
<property name="userType" type="int">
<column name="user_type" />
</property>
<many-to-one class="MasterOrg" fetch="select" name="masterOrg">
<column name="master_org_id" />
</many-to-one>
<many-to-one class="CarrierScac" fetch="select" name="carrierScac">
<column name="scac" />
</many-to-one>
<one-to-one class="AppUserDetails" fetch="select" name="details" constrained="true"/>
<set name="profiles" inverse="true">
<key>
<column name="user_id" />
</key>
<one-to-many class="Profiles" />
</set>
<set name="boilerPlates" inverse="true">
<key>
<column name="user_id" />
</key>
<one-to-many class="BoilerPlate" />
</set>
<set name="rates" inverse="true" >
<key>
<column name="user_id" />
</key>
<one-to-many class="BidToolRates" />
</set>
</class>
在上述休眠映射代码,我想设置MasterOrg字段为空。
您的数据库模式是否允许'master_org_id'列的NULL值?也许它被定义为使用默认值。只要你引用'App_User.masterOrg = null',它应该只是工作 – Brad
@JoeriHendrickx我试着用空值插入空值到数据库中。数据库中的字段的类型为基本int。我需要在int类型的字段中插入null。 –
@Brad是的,我的数据库模式允许master_org_id列的空值。我认为这个问题正在被创建,因为master_org_id的类型是int。它适用于String和其他对象类型 –