I'm creating a new java project that conect to an Oracle XE...
I configured my persistence.xml
with this: <property name="hibernate.connection.autocommit" value="true" />
But on my DAO, if I don't use em.getTransaction().begin();
and em.getTransaction().commit();
my entities isn't persisted...
How to can I use only em.persist(entity);
?
UPDATE:
My persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="simpleRestApplication" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<properties>
<!-- Configuração do driver -->
<property name="hibernate.dialect"
value="org.hibernate.dialect.Oracle10gDialect" />
<property name="hibernate.connection.driver_class"
value="oracle.jdbc.driver.OracleDriver" />
<!-- Configuração de conexão -->
<property name="hibernate.connection.url"
value="jdbc:oracle:thin:@localhost:1521/XE" />
<property name="hibernate.connection.username"
value="system" />
<property name="hibernate.connection.password"
value="********" />
<property name="hibernate.connection.autocommit"
value="true" />
<!-- Configuração do hibernate -->
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.connection.release_mode"
value="auto" />
<property name="current_session_context_class"
value="thread" />
<property name="hibernate.connection.autoReconnect"
value="true" />
</properties>
</persistence-unit>
</persistence>
On my DAO I inject the entityManager with GoogleGuice...
@Inject
private EntityManager em;
My GuiceModule is this...
@Singleton
private static class JPAInitializer {
@Inject
public JPAInitializer(final PersistService service) {
service.start();
}
}
@Override
protected void configure() {
install(new JpaPersistModule("simpleRestApplication"));
bind(JPAInitializer.class).asEagerSingleton();
}