I've got a simple java main which must write bean data on a PostgreSQL database. I use Entity manager to persist or update object. I use hibernate and toplink driver connection which are specified in persistence.xml file. When I call em.persist(obj), nothing is saved on database, I don't know why. here is my simple code:
private static void importa(FileReader f) throws IOException {
EntityManagerFactory emf = Persistence
.createEntityManagerFactory("orpt2");
EntityManager em = emf.createEntityManager();
dispositivoMedico = new DispositivoMedico();
dispositivoMedico.setCategoria("prova");
dispositivoMedico.setCodice("323");
em.persist(dispositivoMedico);
And 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="orpt2">
<class>it.ariadne.orpt2.entities.AccessoriScheda</class>
<class>it.ariadne.orpt2.entities.CampiSchede</class>
<class>it.ariadne.orpt2.entities.CampiSchedeSalvati</class>
<class>it.ariadne.orpt2.entities.CampoAggiuntivo</class>
<class>it.ariadne.orpt2.entities.Categorie</class>
<class>it.ariadne.orpt2.entities.CategorieCampi</class>
<class>it.ariadne.orpt2.entities.CategorieCampiPK</class>
<class>it.ariadne.orpt2.entities.ClasseCivab</class>
<class>it.ariadne.orpt2.entities.DecodificaStato</class>
<class>it.ariadne.orpt2.entities.DispositivoMedico</class>
<class>it.ariadne.orpt2.entities.Ente</class>
<class>it.ariadne.orpt2.entities.FormaNegoziazione</class>
<class>it.ariadne.orpt2.entities.Fornitore</class>
<class>it.ariadne.orpt2.entities.LogSession</class>
<class>it.ariadne.orpt2.entities.Modello</class>
<class>it.ariadne.orpt2.entities.Periodicita</class>
<class>it.ariadne.orpt2.entities.Produttore</class>
<class>it.ariadne.orpt2.entities.Ruolo</class>
<class>it.ariadne.orpt2.entities.RuoloPK</class>
<class>it.ariadne.orpt2.entities.RuoloUtente</class>
<class>it.ariadne.orpt2.entities.Scheda</class>
<class>it.ariadne.orpt2.entities.SchedaSalvata</class>
<class>it.ariadne.orpt2.entities.Tipologia</class>
<class>it.ariadne.orpt2.entities.Utente</class>
<!-- locale 2010--><!-- optsanmatteo_prova300310 -->
<properties>
<property name="hibernate.connection.driver_class"
value="org.postgresql.Driver" />
<property name="hibernate.connection.url"
value="jdbc:postgresql://localhost:5432/optsanmatteo_provaHash" />
<property name="hibernate.connection.password"
value="s4sh4gr3y" />
<property name="hibernate.connection.username"
value="sanmatteo" />
<property name="hibernate.dialect"
value="org.hibernate.dialect.PostgreSQLDialect" />
<property name="toplink.logging.level" value="WARNING" />
<property name="toplink.jdbc.driver"
value="org.postgresql.Driver" />
<property name="toplink.jdbc.url"
value="jdbc:postgresql://localhost:5432/optsanmatteo_provaHash" />
<property name="toplink.jdbc.password" value="s4sh4gr3y" />
<property name="toplink.jdbc.user"
value="sanmatteo" />
</properties>
</persistence-unit>
</persistence>
Thank you for your help.
Mario