JPA 不支持任何自定义隔离级别。您可以扩展该类并重写与连接相关的方法,以便在HibernateJpaDialect
Connection
以下是我写过的东西,但还没有测试过:
public class HibernateExtendedJpaDialect extends HibernateJpaDialect {
@Override
public Object beginTransaction(EntityManager entityManager,
TransactionDefinition definition) throws PersistenceException,
SQLException, TransactionException {
Session session = (Session) entityManager.getDelegate();
DataSourceUtils.prepareConnectionForTransaction(session.connection(), definition);
entityManager.getTransaction().begin();
return prepareTransaction(entityManager, definition.isReadOnly(), definition.getName());
}
}
你把它定义为你的属性:EntityManagerFactory
<property name="jpaDialect">
<bean class="com.company.util.HibernateExtendedJpaDialect" />
</property>