-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate deletes values in one-to-one mapping table
PostPosted: Fri Feb 22, 2008 7:54 am 
Beginner
Beginner

Joined: Sat Dec 01, 2007 4:34 pm
Posts: 20
I've got a problem with Hibernate and a MySQL-table. In my app there are two tables, TravelProduct and Hotel. The relation between these are that Hotel extends TravelProduct in a one-to-one relationship. The tables are mapped as in the code below.

The problem is that when I'm executing a sql-select statement for the first time on the Hotel table, all the values in that table are deleted...

The code for executing the select statement is written below.

The values in table TravelProduct is still there...
I thought it could be inconsistencies between the data in the two tables, but all the deleted rows have related ID-is in both tables.


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>
  <class name="db.TravelProduct" table="TravelProduct">
    <id name="ProductID"  type="long" column="ProductID">
      <generator class="native"/>
    </id>
    <property name="ProductName" column="ProductName"/>
    <property name="ProductComment" column="ProductComment"/>
    <property name="ProductType" column="ProductType"/>
   
    <joined-subclass name="db.Hotel" table="Hotel">
      <key column="HotelID"/>
      <property name="HotelType" column="HotelType"/>
    </joined-subclass>
  </class>
</hibernate-mapping>


Code:
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();
    List hotelList = session.createQuery("from Hotel").list();
    session.getTransaction().commit();


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 22, 2008 9:20 am 
Beginner
Beginner

Joined: Fri May 18, 2007 10:28 am
Posts: 48
Location: Madison, WI
Can you try changing ur map to one-to-one

instead of

<joined-subclass name="db.Hotel" table="Hotel">
<key column="HotelID"/>
<property name="HotelType" column="HotelType"/>
</joined-subclass>

<one-to-one name="db.hotel" table="Hotel" cascade="save-update">

_________________
Please rate if it helped


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 22, 2008 9:21 am 
Beginner
Beginner

Joined: Fri May 18, 2007 10:28 am
Posts: 48
Location: Madison, WI
Can you try changing ur map to one-to-one

replace

<joined-subclass name="db.Hotel" table="Hotel">
<key column="HotelID"/>
<property name="HotelType" column="HotelType"/>
</joined-subclass>

with

<one-to-one name="db.hotel" table="Hotel" cascade="save-update">

_________________
Please rate if it helped


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

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.