我有一个从带有一些空列的表中读取的视图。我有读取这个视图的休眠代码。问题是由于这个空值,休眠无法读取此记录。查看日志我看到以下内容
调试 [http-bio-8080-exec-1][2013-05-20 23:34:16,243][NullableType.java:166] - 返回 null 作为列:address19_0_
它能够读取所有非空列,但是当涉及到在这种情况下为空的地址时,它会引发异常。为什么休眠不能读取这个?
我正在使用 eclipse hibernate 工具生成 POJO 和 hbm.xml 文件。这是休眠工具的 build.xml
<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask">
<classpath>
<fileset dir="C:\eclipse\order\WebContent\WEB-INF\lib">
<include name="**/*.jar" />
</fileset>
</classpath>
</taskdef>
<target name="gen_hibernate" description="generate hibernate classes">
<hibernatetool destdir="C:\eclipse\order\GenCode">
<jdbcconfiguration configurationfile="hibernate.cfg.xml"
packagename="com.order" detectmanytomany="true" />
<hbm2hbmxml destdir="src" />
<hbm2java jdk5="true" destdir="src" />
<hbm2cfgxml destdir="src" />
<hbm2doc />
</hibernatetool>
<copy todir="C:\eclipse\order\src\order\">
<fileset dir="C:\eclipse\order\GenCode\src\com\order\">
<include name="**/*.java" />
<include name="**/*.hbm.xml" />
</fileset>
</copy>
<copy file="C:\eclipse\order\GenCode\src\hibernate.cfg.xml" todir="C:\eclipse\order\src\" />
</target>
这是我为视图生成的 hbm.xml,它使用复合 ID 生成
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated May 20, 2013 11:26:25 PM by Hibernate Tools 3.2.0.CR1 -->
<hibernate-mapping>
<class name="com.order.VOrderdetail" table="v_orderdetail" catalog="order">
<composite-id name="id" class="com.order.VOrderdetailId">
<key-property name="orderId" type="int">
<column name="orderId" />
</key-property>
<key-property name="userId" type="int">
<column name="userId" />
</key-property>
<key-property name="createDate" type="date">
<column name="createDate" length="0" />
</key-property>
<key-property name="description" type="string">
<column name="description" length="65535" />
</key-property>
<key-property name="addressLine1" type="string">
<column name="addressLine1" length="100" />
</key-property>
<key-property name="addressLine2" type="string">
<column name="addressLine2" length="100" />
</key-property>
<key-property name="city" type="string">
<column name="city" length="100" />
</key-property>
<key-property name="state" type="string">
<column name="state" length="10" />
</key-property>
<key-property name="zipCode" type="string">
<column name="zipCode" length="10" />
</key-property>
</composite-id>
</class>
</hibernate-mapping>