Я создаю новый проект Java, который подключается к Oracle XE ...
Я настроил persistence.xml
следующим образом: <property name="hibernate.connection.autocommit" value="true" />
Но в моем DAO, если я не использую em.getTransaction().begin();
и em.getTransaction().commit();
, мои сущности не сохраняются ...
Как я могу использовать только em.persist(entity);
?
UPDATE
Моя настойчивость. 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>
В моем DAO я внедряю entityManager с GoogleGuice ...
@Inject
private EntityManager em;
Мой GuiceModule это ...
@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();
}