views:

27

answers:

2

I'm using Embedded Derby DB with hibernate. I'm saving some entities to database. After shutting down the application there is no entities in DB. Why it could be so?

Below my Hibernate configuration

<?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"&gt;   

<hibernate-configuration>    
  <session-factory>    
    <property name="show_sql">true</property>  
    <property name="format_sql">true</property>  
    <property name="dialect">org.hibernate.dialect.DerbyDialect</property>
    <property name="connection.driver_class">org.apache.derby.jdbc.EmbeddedDriver</property>   
    <property name="connection.url">jdbc:derby:\bases\localbase;create=true</property>  
    <property name="connection.username"></property>
    <property name="connection.password"></property>    
    <property name="hibernate.hbm2ddl.auto">validate</property>
    <mapping class="com.example.model.HistoryItem"/>  
    <mapping class="com.example.model.User"/>  
    <mapping class="com.example.model.BaseAbstractEntity"/>
  </session-factory>  
</hibernate-configuration>   
+1  A: 

This is weird because Derby sync to the disk after each commit by default (unless you set the property derby.system.durability=test). And your url looks correct (although I would use forward slashes).

This begs the question: how do you managed transactions? Are you sure that you are committing them?

Pascal Thivent
I didn't use transctions. I'll try it now.java code to add object, for example: public final static SessionFactory sf = HibernateUtil.getSessionFactory(); public Long addObject(T object) throws DAOException { Session s = sf.openSession(); s.save(object); s.close(); return object.getId(); }
Ramil
Thanks. Transactions helps.
Ramil
A: 

Perhaps you are looking in the wrong place. Perhaps the Hibernate application is creating a Derby database in one location on your hard disk, but when you look for the database contents later, you are looking in a different location on your hard disk. Since your Derby URL says "create=true", Derby will quietly create a new empty database for you if you don't get exactly the same location specification as in your original app.

Bryan Pendleton
No. I'm work with right database.
Ramil