Hibernate version: 3.2.1 (and also 3.2.4.SP1)
Mapping documents:
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="nl.semlab.viewerpro.client.core.event">
<class name="DefaultEvent" table="event">
<id name="id" type="long" unsaved-value="-1">
<generator class="native" />
</id>
<property name="name" type="string" length="100" not-null="true" />
<property name="description" type="string" />
<!-- TODO: figure out why we have to use lazy="false" here -->
<set name="eventActions" table="eventAction" lazy="false" cascade="all">
<key column="eventId" />
<one-to-many class="nl.semlab.viewerpro.client.core.eventaction.DefaultEventAction" />
</set>
<!-- TODO: figure out why we have to use lazy="false" here -->
<set name="eventInstances" table="eventInstance" lazy="false" cascade="all">
<key column="eventId" />
<one-to-many class="nl.semlab.viewerpro.client.core.eventinstance.DefaultEventInstance" />
</set>
</class>
</hibernate-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="nl.semlab.viewerpro.client.core.eventaction">
<class name="DefaultEventAction" table="eventAction">
<id name="id" type="long" unsaved-value="-1">
<generator class="native" />
</id>
<many-to-one name="action" class="nl.semlab.viewerpro.client.core.action.DefaultAction" lazy="false" />
<property name="value" type="string" />
</class>
</hibernate-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="nl.semlab.viewerpro.client.core.eventinstance">
<class name="DefaultEventInstance" table="eventInstance">
<id name="id" type="long" unsaved-value="-1">
<generator class="native" />
</id>
<many-to-one name="event" class="nl.semlab.viewerpro.client.core.event.DefaultEvent" lazy="false" />
<many-to-one name="newsItem" class="nl.semlab.viewerpro.client.core.news.DefaultNewsItem" lazy="false" />
<property name="selectedText" type="string" />
</class>
</hibernate-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="nl.semlab.viewerpro.client.core.action">
<class name="DefaultAction" table="action">
<id name="id" type="long" unsaved-value="-1">
<generator class="native" />
</id>
<property name="name" type="string" length="100" not-null="true" />
<property name="description" type="string" />
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
Session session = getSessionFactory().openSession();
Transaction tx = session.beginTransaction();
try
{
session.saveOrUpdate(p_event);
Logger.getLogger(EventManagerDaoHibernate.class).info("saving: " + p_event.getName() + "; id: " + p_event.getId());
}
catch (HibernateException he)
{
Logger.getLogger(EventManagerDaoHibernate.class).info("error saving event", he);
tx.rollback();
}
finally
{
tx.commit();
session.close();
}
Full stack trace of any exception that occurs:None.
Name and version of the database you are using:HSQLDB-1.8.0.7
The generated SQL (show_sql=true):Code:
INFO [2007-07-11 12:37:10,158] EventManagerDaoHibernate.saveEvent(93) | saving: Assings; id: 1
Hibernate: update event set name=?, description=? where id=?
Hibernate: update eventAction set action=?, value=? where id=?
INFO [2007-07-11 12:37:10,170] EventManagerDaoHibernate.saveEvent(93) | saving: Release; id: 2
Hibernate: update event set name=?, description=? where id=?
Hibernate: update eventAction set action=?, value=? where id=?
INFO [2007-07-11 12:37:10,172] EventManagerDaoHibernate.saveEvent(93) | saving: Upgrade; id: 3
Hibernate: update event set name=?, description=? where id=?
Hibernate: update eventAction set action=?, value=? where id=?
INFO [2007-07-11 12:37:10,173] EventManagerDaoHibernate.saveEvent(93) | saving: Downgrade; id: 4
Hibernate: update event set name=?, description=? where id=?
Hibernate: update eventAction set action=?, value=? where id=?
INFO [2007-07-11 12:37:10,182] EventManagerDaoHibernate.saveEvent(93) | saving: 123; id: 5
Hibernate: insert into event (id, name, description) values (null, ?, ?)
Hibernate: call identity()
Hibernate: insert into eventAction (id, action, value) values (null, ?, ?)
Hibernate: call identity()
Hibernate: update eventAction set eventId=? where id=?
The problem:I am trying to save a few events when exiting my application, the first four are already in my HSQLDB at load time, so they are being updated. The last one is new and should be saved to HSQLDB. However, when I start my application again the new event is not in HSQLDB. These are my HSQLDB specific settings:
Code:
config.setProperty("hibernate.hbm2ddl.auto", "update");
config.setProperty("cache.provider_class","org.hibernate.cache.NoCacheProvider");
I tried doing this after saving the events:
Code:
try
{
Session session = configuration.getSessionFactory().openSession();
Transaction tx = session.beginTransaction();
session.connection().createStatement().execute("SHUTDOWN");
tx.commit();
}
catch (HibernateException ex)
{
ex.printStackTrace();
}
catch (SQLException ex)
{
ex.printStackTrace();
}
However, this results in the following error:
Code:
java.lang.IllegalArgumentException: interface org.hibernate.jdbc.ConnectionWrapper is not visible from class loader
I tried version 3.2.4.SP1 of Hibernate with the same results.
This is how the connection to HSQLDB is made:
Code:
jdbc:hsqldb:file:demo
--
Best regards,
Jethro Borsje