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