-->
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.  [ 12 posts ] 
Author Message
 Post subject: Hibernate + Embedded HSQL flushing delay problem
PostPosted: Tue Jul 31, 2007 8:19 pm 
Newbie

Joined: Wed Sep 20, 2006 10:07 pm
Posts: 3
I've being using hibernate 3.2.4.sp1 + Hibernate Annotation 3.3.0.ga1 + hsql - 1.8.0.7 (standalone mode) as a lightweight backend for a small swing desktop application.

I initialize hibernate using the standard HibernateUtil approach (which keep a static SessionFactory). everything works fine except data doesn't get written to the db file couple of seconds after the transaction. so If I start up the program and write some record to db and exit program immediately, nothing gotten written to db. If I watch the file closely, seems it takes 6-8 seconds until HSQL actually write the file after the transaction commit.

I tried every possible setup properties for HSQL, for example, I set jdbc_batch_size to 0, and set connection.pool_size to 1. just fix this problem at all.

here's my hibernate.cfg.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
      "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
      "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>       
    <session-factory>
       <property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
        <property name="hibernate.connection.username">sa</property>
      <property name="hibernate.connection.password"></property>
      <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
        <property name="hibernate.hbm2ddl.auto">update</property>
      <property name="connection.pool_size">1</property>
      <property name="hibernate.jdbc.batch_size">0</property>
      <property name="current_session_context_class">thread</property>
      <property name="hibernate.autocommit">false</property>
        <mapping class="model.Tag"/>
        <mapping class="model.Item"/>
        <mapping class="Folder"/>       
      <mapping class="GameSetting"/>       
    </session-factory>
</hibernate-configuration>

The connection.url is set later in HibernateUtil
Code:
public class HibernateUtil {

   private static SessionFactory sessionFactory;

   private HibernateUtil() {
      // do nothing
   }

   public static void init() {
      try {
         AnnotationConfiguration cfg = new AnnotationConfiguration();
         cfg.configure("/../config/hibernate.cfg.xml");
         Properties extraProperties = new Properties();
         extraProperties.put("hibernate.connection.url",
               "jdbc:hsqldb:file://C:/oref");
         
         cfg.addProperties(extraProperties);
         sessionFactory = cfg.buildSessionFactory();         
      } catch (HibernateException ex) {
         ex.printStackTrace();
         throw new RuntimeException("Exception building SessionFactory: "
               + ex.getMessage(), ex);
      }
   }

   public static SessionFactory getSessionFactory() {
      if (sessionFactory == null)
         init();
      return sessionFactory;
   }

}


Any Thoughts? Thanks a lot


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 01, 2007 5:30 am 
Newbie

Joined: Wed Aug 01, 2007 5:17 am
Posts: 6
Hi onsight,
I'm stucked with the same problem you got.

I was working on an SWT application that was using an older version of HSQL. I upgraded the version of HSQL to 1.8.0.7 as you and also the version of Hibernate to 3.2.4.sp1.

Now if I modify some records and exit immediately the changes aren't written in the DB.

Have you find any solution?

Thanks for any suggestion!


Top
 Profile  
 
 Post subject: Hibernate + HSQL = don't save on DB?
PostPosted: Wed Aug 01, 2007 11:19 am 
Newbie

Joined: Wed Aug 01, 2007 5:17 am
Posts: 6
Hi all,
I searched around and make some tests but I have still the same problem: hibernate don't save on DB.

I'm working on an SWT application that uses Hibernate and HSQLDB.
When I was working with HSQLDB version 1.7.2.11 and Hibernate 3.0.5 everithing was ok, but when i upgraded to HSQLDB version 1.8.0.7 and Hibernate 3.2.5 I found that my changes weren't saved on DB.

I tried various version of HSQLDB and Hibernate, but the problem still remain because I have to use a version of HSQLDB >= 1.8.0.2

Here is my hibernate.cfg.xml:

Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.bytecode.use_reflection_optimizer">false</property>
        <property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
        <property name="hibernate.connection.url">jdbc:hsqldb:C:/nuovoDBStime/stime</property>
        <property name="hibernate.connection.username">sa</property>
        <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>   

        <mapping resource="it/eng/cmm/stime/model/TSpAttStimaProg.hbm.xml" />
        ....
        <mapping resource="it/eng/cmm/stime/model/TSpRilasci.hbm.xml" />
       
    </session-factory>
</hibernate-configuration>



And here there is a simple test:

Code:
session = HibernateUtil.getSession();
      tx = session.beginTransaction();
      
      String codProg = "LL05";
      Integer versStima = 2;
      short progrOggStima = 3;
      
      BigDecimal value = new BigDecimal(1335);

      TSpValOggGlobStimaId id = new TSpValOggGlobStimaId(codProg, versStima, progrOggStima);
      TSpValOggGlobStima valOggGlobStima = (TSpValOggGlobStima)session.get(TSpValOggGlobStima.class, id);
      
      System.out.println(">>>> "+ valOggGlobStima.getValStima()); /// first output = 333
      valOggGlobStima.setValStima(value);
      System.out.println(">>>> "+ valOggGlobStima.getValStima()); /// second output = 1335
      
      tx.commit();
      session.close();


If I run this snippet two times the first output should be the first time 333 and the second time it should be 1335, but it is not!

No errors given from hibernate...

Thanks for any ideas,
Luca.


Top
 Profile  
 
 Post subject: More Information
PostPosted: Wed Aug 01, 2007 12:19 pm 
Newbie

Joined: Fri Apr 07, 2006 11:29 am
Posts: 17
What is the actual logic that isn't saving? Please paste code regarding the save operations. From the code snipit you provided, you are updating the value in your example that you pasted, but you never call save on the object. You should be calling:

Code:
session.save(valOggGlobStima);


All your code should do is make the state of the TSpValOggGlobStima dirty. As far as why the output does not change on your system outs, I would look at the setter on the your VO to make sure that it actually is setting the internal property.


Top
 Profile  
 
 Post subject: hibernate3.2.x is not refresh updated data
PostPosted: Wed Aug 01, 2007 1:46 pm 
Newbie

Joined: Wed Aug 01, 2007 1:35 pm
Posts: 3
hi,
I have similar problem with updated data not refersh even the code call save() function.

Environment: Hibernate 3.2.5, Ehcache1.3, spring2.0 and jboss4.2.1

when I update a status to a current data and call save on the object. I retrieve data (find) from the same table for display. But the resultlist is still contained the old data. The updated data is still in the list.
It works in 3.1.3, the status was updated and when call find the latest resultlist is returned.
But in 3.2.x, the updated data still in the resultlLst after another select (find) utile I manually reload the page.

here is some code example:

//daoCustomerContent is a hibernate data object
customerContent.setCustomerContentStatus("SUBMITTED");
daoCustomerContent.save(customerContent);//save
// hibernate find
getHibernateTemplate().executeFind(new Page(_queryString, _values, _page, _pageSize));
// the update data update to "submitted" still exist in this result List


please advice, Thank you


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 01, 2007 2:10 pm 
Newbie

Joined: Wed Sep 20, 2006 10:07 pm
Posts: 3
Glad to know there are people out there struggling on problems like mine,
here's a typical save I do in my code

Code:
Session session = HibernateUtil.getSessionFactory().openSession();
try {
   session.beginTransaction();
   item = (Item) session.get(Item.class, item.getId());                  
   item.setName("newName");
   session.saveOrUpdate(item);
   session.getTransaction().commit();

} catch (Exception ex) {
   ex.printStackTrace();

} finally {
   session.close();
}


And I aways close SessionFactory when the applicatoin shutdown


Top
 Profile  
 
 Post subject: Hibernate + HSQL = don't save on DB?
PostPosted: Thu Aug 02, 2007 3:35 am 
Newbie

Joined: Wed Aug 01, 2007 5:17 am
Posts: 6
Hi bradsdavis,
Thanks for your reply, but the problem still remain if i call

Code:
session.save(valOggGlobStima);


The object loaded from session.get() is in a persistent state yet, and if I call transaction.commit() the changes should be written in the database also without calling session.save(), I think. Am I wrong?
Anyway I don't see any change using the two methods.

Now I will try other version of Hibernate to see if this is the cause of this problem.

See you soon!


Top
 Profile  
 
 Post subject: Hibernate + HSQL = don't save on DB?
PostPosted: Thu Aug 02, 2007 6:12 am 
Newbie

Joined: Wed Aug 01, 2007 5:17 am
Posts: 6
Well,
I tried different combination of HSQLDB and Hibernate.

The solution that worked for my small test is using HSQLDB version 1.7.3.3 and Hibernate version 3.0.5.

If I try to use a version of HSQLDB >= 1.8.0.1 the changes aren't written in the DB, but I get no errors. If I try to use a version of Hibernate >= 3.1.3, Hibernate can't find the tables.

Is there some change that I have ignored upgrading the version of HSQLDB?

I have to use a version of HSQLDB >= 1.8.0.2, I can't think that such a problem is a bug! What I'm doing wrong?

Help, please.


Top
 Profile  
 
 Post subject: find workaround
PostPosted: Thu Aug 02, 2007 8:51 am 
Newbie

Joined: Wed Aug 01, 2007 5:17 am
Posts: 6
Hi,

I find some interesting information in the documentation about WRITE_DELAY
and changed made from version 1.7.2.
In particular setting WRITE_DELAY to FALSE solved my problems and changes are immediately written on the database.

SQL command:
Code:
SET WRITE_DELAY FALSE;


N.B. If I open the database in server mode everything is ok, but I have to use standalone mode.

Hope this help, bye!


Top
 Profile  
 
 Post subject: updated data not refersh in hibernate 3.2.3 or later
PostPosted: Thu Aug 02, 2007 10:47 am 
Newbie

Joined: Wed Aug 01, 2007 1:35 pm
Posts: 3
Environment: Hibernate 3.2.5, Ehcache1.3, spring2.0 and jboss4.2.1 and Oracle9. Not use HSQLDB

Hibernate 3.2.3 or later version + Spring Frame 2.0.

In hibernate 3.1 version, the data updated and return a correct new resultset.
in hiber nate 3.2.3 or later, the data updated but the resultset didn't get refresh. if I reload the page, the resultset is updated.

//daoCustomerContent is a hibernate data object
customerContent.setCustomerContentStatus("SUBMITTED");
//save: spring framework, hibernate3 DAO support
//getHibernateTemplate().saveOrUpdate(_entity)
daoCustomerContent.save(customerContent);//save
//select spring fram work hibernate3 DAO support

org.springframework.orm.hibernate3.support.getHibernateTemplate().executeFind(
new Page(_queryString, _values, _page, _pageSize))

// the update data update to "submitted" still exist in this result List


does hibernate 3.2.3 or later compatible with spring Frame work 2.0.6?



thank you


Top
 Profile  
 
 Post subject: solution on update delay
PostPosted: Fri Aug 03, 2007 6:16 pm 
Newbie

Joined: Wed Aug 01, 2007 1:35 pm
Posts: 3
hi, all

subject : update data not refersh in hibernate 3.2.3 or later version

In Hibernate3.1 the data update gets refresh immediately with call flush() BUT it seems like 3.2.3 or latter require flush() to avoid update delay.

after I added super.getHibernateTemplate().flush(); afer I call save().
all date refresh immediately.


thanks


Top
 Profile  
 
 Post subject: Re: Flushing Delay Problem
PostPosted: Fri Aug 31, 2007 3:09 pm 
Newbie

Joined: Fri Aug 31, 2007 3:02 pm
Posts: 1
I'm only addressing the HSQLDB-specific issues, not whether and when Hibernate flushes. I'm a member of the HSQLDB development group.

For cases where a HSQLDB :file: URL is used with the shutdown connection property, I believe the root problem is that one or more of the intervening products (app server, ORM, data pooling) do not close all physical connections to the database when the app is stopped, or before JVM exit. The worse offender I have witnessed is Hibernate, which starts up an undocumented managing connection when you initiate your factory, and this connection is not closed when the using application is shut down. A work around is to turn down WRITE_DELAY so that even when there is no clean shutdown, your changes will still be persisted.

For cases where a HSQLDB :hsql: URL is used, the problem is not with the client-side :hsql: setup, but with the HSQLDB server-side setup. Unless you are running a distributed app server, your app code would be more straight forward and efficient by using :file:, regardless of whether you run a HSQLDB server to provide for remote access. If you are running a distributed app server and need to use :hsql:, it would very likely improve your design to run your HSQLDB server in a standalone JVM, especially if you are experiencing problems like those in this thread. (Depending on how hsqldb.jar is bundled and your app server's class loading strategy, you could hit visibility issues when using :file:). If you run your HSQLDB Server standalone, you can troubleshoot database problems and tune your DB independently of pooling, app server, ORMs, etc.


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