0

I have a table DEVICE which has a unique id of DEVICEID. I have a second table called DEVICEINFO whose primary key is a sequence DEVICEINFOSEQ but this info table also has a DEVICEID field which is a foreign key pointing back to DEVICE. In the DEVICE HBM I have the following for deviceinfo

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-lazy="true"
package="com.xxx.xxx.xxx">
<class name="Device" table="DEVICE" dynamic-update="true">
    <id name="dString" column="DEVICEID" type="java.lang.String"
        unsaved-value="null" length="9">
        <generator class="assigned"/>
    </id>
....
<many-to-one name="deviceInfo" class="DeviceInfo"
        outer-join="true" foreign-key="deviceId"  >
    </many-to-one>

And my device info hbm is as follows

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-lazy="true" package="com.xxx.xxx.xxx">
<class name="DeviceInfo" table="DEVICEINFO" dynamic-update="true">
    <id name="id" column="DID" type="integer">
        <generator class="native">
            <param name="sequence">DEVICEINFOSEQ</param>
        </generator>
    </id>

    <property name="deviceId" column="DEVICEID" type="string"
        length="32">
    </property>
    <property name="somefield" column="SOMEFIELD" type="string" length="30" />
</class>

One device will only have 1 entry in the Deviceinfo table but a device need not have an entry at all. Not all devices have device info. But if the info is present, we have to retrieve it. The info is updated from another source and this HBM should actually if possible prevent any updates. Is many-to-one correct? Maybe I should use one-to-many?

if I use the above HBM, I get

org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query; SQL

p0tta
  • 1,461
  • 6
  • 28
  • 49
  • can u post some more code – PSR Apr 09 '13 at 04:01
  • one device may have multiple deviceInfo? – Hunter Zhao Apr 09 '13 at 04:10
  • Added more code. one device can only have one device info. But there can be a device which doesn't have any deviceinfo. So for deviceID 123 there can be a row in the deviceinfo table with sequence say 1 and deviceID but for deviceID 234, there need not be an entry in the deviceinfo table. – p0tta Apr 09 '13 at 07:06
  • I also tried this for deviceinfo inside device and it didn't work – p0tta Apr 09 '13 at 07:07

0 Answers0