hibernate无法使用null列读取视图

时间:2013-05-21 03:45:38

标签: hibernate

我有一个视图,它从表中读取一些空列。我有hibernate代码读取此视图。问题是由于这个空值,hibernate无法读取此记录。查看日志,我看到以下

  

DEBUG [http-bio-8080-exec-1] [2013-05-20   23:34:16,243] [NullableType.java:166] - 以列为单位返回null:   address19_0 _

它能够读取所有非空列,但是当涉及到null的地址时,它会抛出异常。为什么hibernate无法读取这个?

我正在使用eclipse hibernate工具生成POJO和hbm.xml文件。这是hibernate工具的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>

1 个答案:

答案 0 :(得分:2)

映射到包含空值的列的属性不应用作复合ID的一部分。有关此用例的拒绝票证HHH-1109