-->
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: joined-subclass, changing between superclass and subclass?
PostPosted: Tue Jun 21, 2011 4:27 am 
Beginner
Beginner

Joined: Thu Oct 16, 2008 11:19 am
Posts: 23
Location: Norway
We have a problem with the usage of joined-subclass when changing between the superclass and subclass for persistent entities. We use the following mapping:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
   
<hibernate-mapping package="whatever.domain">
    <class name="Sensor" table="SENSOR" lazy="true">
        <id name="id" column="ID" type="long">
            <generator class="sequence">
                <param name="sequence">SENSOR_SEQ</param>
            </generator>
        </id>
        <property name="date" type="date" column="DATE"/>
        <joined-subclass name="CamSensor" table="CAM_SENSOR" lazy="true">
            <key column="ID"/>
            <many-to-one name="format" column="FORMAT" not-null="true" class="PicFormatType" lazy="false"/>
            <property name="infrared" type="character" column="INFRARED"/>
       </joined-subclass>
    </class>
</hibernate-mapping>


A camera sensor (camsensor) is a sensor with some more attributes and relations. We would like to be able to change a persistent sensor into camera sensor, and vice versa. We do the former by retrieving a sensor object from the database, copying all information contained in the object into a camera sensor object, and try to save the new camera sensor to the database. This does however not work, and we get the following exception.

Code:
Could not flush session:

org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [whatever.domain.CamSensor#21263]

Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [whatever.domain.CamSensor#21263]


When we want to change the type of a camera sensor into a regular sensor, we do it the same way. We retrieve the camera sensor from the database, copy all relevant values into a new sensor object, and save the new sensor back into the database. This does not give us any exception, but behaves unlike we expect. The information in our sensor-table is updated, but the entry in the cam_sensor-table is not altered, so when Hibernate retrieves the object again later, it appears to be a camera sensor.

Are we doing something the wrong way, or have we missed an important bit? Suggestions would be appreciated!


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.