-->
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: HSQLDB file persistence strange behavior
PostPosted: Wed May 05, 2010 6:15 am 
Newbie

Joined: Thu Jan 21, 2010 5:13 pm
Posts: 7
Dear everyone. I have code similar to this pseudocode:

Get session 1.
Create transaction 1.
Create an entity.
Commit transaction 1.
Close session 1.

Get session 2.
Create transaction 2.
Fetch the number of entities.
Commit transaction 2.
Close session 2.

Get session 3.
Create transaction 3.
Create an entity.
Commit transaction 3.
Close session 3.

It works as expected. However, if I throw an exception after "Close session 2" something unexpected happens.

If the persistence mechanism is working in server mode, the first entity is saved and persisted, because the transaction is committed. That's OK. But in file mode, it is not persisted at all!

I would expect it to be persisted because the transaction is committed. More, I would expect the file behavior to be consistent with the server behavior. But it isn't - why?

This is how I use server mode:
Code:
<property name="hibernate.connection.url">jdbc:hsqldb:hsql://localhost/xdb</property>


And this is how I use the file mode:
Code:
<property name="hibernate.connection.url">jdbc:hsqldb:file:db\filedb;shutdown=true</property>

As you can see, I was forced to use shutdown=true, otherwise the changed were not saved at all, with the exception or without it.

I'm using hibernate 3.2.4.ga and hsqldb 1.8.0.7.
This is also active:
Code:
<property name="hibernate.hbm2ddl.auto">update</property>


Thanks for any hints.

Here's the code with the exception:

Code:
public static void main(String[] args) {
      Session session = HibernateUtil.getSessionFactory().openSession();
      Transaction tx = session.beginTransaction();
      Message message = new Message("Hello World");
      Long messageId = (Long) session.save(message);
      tx.commit();
      session.close();

      Session newSession = HibernateUtil.getSessionFactory().openSession();
      Transaction newTx = newSession.beginTransaction();
      List<Message> messages = newSession.createQuery(
            "from Message m order by m.text asc").list();
      System.out.println("# of messages: " + messages.size());
      for (Message aMessage : messages) {
         System.out.println(aMessage.getText());
      }
      newTx.commit();
      newSession.close();
      if (true) {
         throw new RuntimeException("Uh oh");
      }

      Session thirdSession = HibernateUtil.getSessionFactory().openSession();
      Transaction thirdTx = thirdSession.beginTransaction();
      message = (Message) thirdSession.get(Message.class, messageId);
      message.setText("Greetings Earthling");
      message.setNextMessage(new Message("Take me to your leader"));
      thirdTx.commit();
      thirdSession.close();

      HibernateUtil.shutdown();


Top
 Profile  
 
 Post subject: Re: HSQLDB file persistence strange behavior
PostPosted: Sun May 16, 2010 1:26 pm 
Newbie

Joined: Thu Jan 21, 2010 5:13 pm
Posts: 7
OK, in case someone has a similar problem, I posted an entry with a workaround:
http://blog.m1key.me/2010/05/hsqldb-fil ... to-on.html


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.