-->
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.  [ 3 posts ] 
Author Message
 Post subject: HSQLDB issue when using hibernate only
PostPosted: Wed Jun 10, 2009 3:51 pm 
Newbie

Joined: Wed Jun 10, 2009 3:43 pm
Posts: 1
I have installed and run the HSQLDB in my local machine.

I created a table and inserted some data. In order to retrieve this data, first I tested with JDBC code and it returned the exact result.
Code:
Class.forName("org.hsqldb.jdbcDriver");
         
            System.out.println("Driver Loaded.");
            conn = DriverManager.getConnection("jdbc:hsqldb:hsql://141.161.18.173:9001/xdb", "sa", "");
           
            st = conn.createStatement();
            ResultSet rs = st.executeQuery("select * from test3");
           
          while (rs.next()) {
             System.out.println("value = "+rs.getString(2));
               }


Then to I used the hibernate to get this data, one strange thing happened, i.e. the data is lost from the data base side too. Then I put run the progam in debug mode then I came to know when we create the sessionfactory, the data is loosing in all tables which are mapped to hibernate.cfg.xml file. Strange thing.

Here is the cfg file:
Code:
<session-factory>
        <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
        <property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
        <property name="hibernate.connection.url">jdbc:hsqldb:hsql://141.161.18.173:9001/xdb</property>
        <property name="hibernate.connection.username">sa</property>
        <property name="hibernate.connection.password"></property>
        <property name="hibernate.connection.pool_size">10</property>
        <property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
        <property name="hibernate.hbm2ddl.auto">create</property>
        <property name="hibernate.show_sql">true</property>
        <property name="hibernate.current_session_context_class">thread</property>
        <mapping resource="edu/gu/Keywords.hbm.xml"/>
       
    </session-factory>


and Test class to get the result.
Code:
SessionFactory factory = HibernateUtil.getSessionFactory(); // when this statement executed, the data is loosing.

       Session session = factory.getCurrentSession();

        session.beginTransaction();


        List result = session.createQuery("from Keywords").list();
        for (int i = 0; i < result.size(); i++) {
            Keywords theEvent = (Keywords) result.get(i);
            System.out.println("Keywords: " + theEvent.getName());
        }
        session.getTransaction().commit();


What could be the problem? I didn't find the sufficient solution in web too. Please someone help on this.


Top
 Profile  
 
 Post subject: Re: HSQLDB issue when using hibernate only
PostPosted: Thu Jun 11, 2009 12:21 am 
Newbie

Joined: Tue Jun 09, 2009 11:00 pm
Posts: 2
Please check if you have specified all the table columns as <property> in your mapping file.


Top
 Profile  
 
 Post subject: Re: HSQLDB issue when using hibernate only
PostPosted: Sat Jun 20, 2009 11:15 am 
Newbie

Joined: Sun Jun 03, 2007 5:01 pm
Posts: 6
I think the problem might be:
Code:
<property name="hibernate.hbm2ddl.auto">create</property>

Which tells the SessionFactory to send the DDL commands to the DB to (re)create the schema whenever you create one.

See: http://docs.jboss.org/hibernate/stable/core/reference/en/html/configuration-optional.html


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