-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate does not save to HSQLDB
PostPosted: Wed Jul 11, 2007 6:49 am 
Newbie

Joined: Wed Jul 11, 2007 6:06 am
Posts: 15
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


Last edited by jethro on Thu Jul 12, 2007 3:26 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 12, 2007 3:24 am 
Newbie

Joined: Wed Jul 11, 2007 6:06 am
Posts: 15
Hi everybody,

I figured it out! The following code does the trick when shutting down your application:
Code:
try
{
   Session session = configuration.getSessionFactory().getCurrentSession();
   Transaction tx = session.beginTransaction();
   session.createSQLQuery("SHUTDOWN").executeUpdate();
   tx.commit();
}
catch (HibernateException ex)
{
   ex.printStackTrace();
}

--
Best regards,
Jethro Borsje


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.