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();