How to setup an hibernate project using annotations compliant with JPA2.0
- by phmr
I would like to setup an hibernate project, for this I use the lastest hibernate 3.5-Final. BTW my IDE is Netbeans.
The problem is that each time a run the application, it seems to start from a fresh database whatever db backend I use (I tried hsqldb & sqlite):
here is my persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="PMMPU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>model.Extrait</class>
<class>model.Mot</class>
<class>model.Prefixe</class>
<class>model.Suffixe</class>
<class>model.Texte</class>
<properties>
<property name="hibernate.dialect" value="dialect.SQLiteDialect"/>
<property name="hibernate.connection.username" value=""/>
<property name="hibernate.connection.driver_class" value="org.sqlite.JDBC"/>
<property name="hibernate.connection.password" value=""/>
<property name="hibernate.connection.url" value="jdbc:sqlite:test.db"/>
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit>
</persistence>
I tried to change hibernate.hbm2ddl.auto value.
I got a HibernateUtil class which takes care of creating the emf & em:
public class HibernateUtil {
private static EntityManagerFactory emf = null;
private static EntityManager em = null;
public static EntityManagerFactory getEmf()
{
if(emf == null)
emf = Persistence.createEntityManagerFactory("PMMPU");
return emf;
}
public static EntityManager getEm()
{
if(em == null)
em = getEmf().createEntityManager();
return em;
}
What did a I do wrong ?
edit1: further research with mysql lead me to think that the problem is related to sqlite & hsqldb interaction with hibernate 3.5