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.