我正在尝试在我的项目中设置 hibernate + JPA。但是当我尝试插入时没有任何反应,我进入休眠 jar 的源代码,我看到休眠将我的实体识别为瞬态状态而不是持久状态。
我的一些配置是:
我的春天背景:
<jee:jndi-lookup id="integrationDS" jndi-name="java:jboss/datasources/integrationDS" expected-type="javax.sql.DataSource"/>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="integrationDS" />
</bean>
我的持久性xml:
<persistence 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_2_0.xsd"
version="2.0">
<persistence-unit name="integrationDS">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jboss/datasources/integrationDS</jta-data-source>
<class>com.integration.domain</class>
<class>com.integration.domain.myentity</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<validation-mode>NONE</validation-mode>
<properties>
<property name="javax.persistence.validation.mode" value="none" />
<property name="hibernate.validator.autoregister_listeners" value="false" />
<property name="hibernate.generate_statistics" value="true" />
<property name="hibernate.jdbc.batch_size" value="100"/>
<property name="hibernate.validator.apply_to_ddl" value="false" />
<property name="hibernate.dialect" value="com.integration.util.MysqlBitBooleanDialect" />
<property name="hibernate.id.new_generator_mappings" value="false" />
<property name="hibernate.hbm2ddl.auto" value="validate" />
<property name="hibernate.cache.use_second_level_cache" value="false" />
<property name="hibernate.cache.use_query_cache" value="false" />
<property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform" />
<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
</properties>
</persistence-unit>
我的代码:
@Transactional
public <T> T executeSaveInTransaction(T entity) {
try {
getDao().persist(entity);
return entity;
} catch (RuntimeException e) {
//rollbackTransaction();
throw e;
} catch (Exception e) {
//rollbackTransaction();
throw new DaoException(e);
} finally {
// clear resources
}
}
任何想法?
谢谢,