user1241438
user1241438

Reputation: 1543

hibernate cannot read view with null column

I have a view which reads from table with some null columns. I have hibernate code which reads this view. The issue is hibernate is not able to read this record due to this null value. Looking at the logs i see the following

DEBUG [http-bio-8080-exec-1][2013-05-20 23:34:16,243][NullableType.java:166] - returning null as column: address19_0_

It is able to read all the non null columns but when it comes to address which is null in this case it throws exception. Why is hibernate not able to read this?

I am generating the POJO and hbm.xml file using eclipse hibernate tool. Here is the build.xml for the hibernate tool

<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>

And here is my generated hbm.xml for the view, it is generating with composite 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>

Upvotes: 1

Views: 748

Answers (1)

Mikko Maunu
Mikko Maunu

Reputation: 42094

Properties that are mapped to columns containing null values should not be used as a part of composite id. There is rejected ticket HHH-1109 about this use case.

Upvotes: 2

Related Questions