These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: What hibernate mapping to use?
PostPosted: Tue Apr 09, 2013 9:43 pm 
Newbie

Joined: Tue Apr 09, 2013 9:40 pm
Posts: 2
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

Code:
<?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"
           not-found="ignore" not-null="false" insert="false" update="false" foreign-key="deviceId"  >
        </many-to-one>


And my device info hbm is as follows

Code:
<?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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.