我一直在尝试:
@Transactional(isolation=Isolation.SERIALIZABLE, rollbackFor={Exception.class}, propagation=Propagation.REQUIRES_NEW)
关于我的服务方式,但spring抱怨说:
Standard JPA does not support custom isolation levels - use a special JpaDialect
我该如何解决?
JPA不支持自定义隔离级别。你可以扩展HibernateJpaDialect类并覆盖与连接有关的方法,以便可以在Connection
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:
EntityManagerFactory:
<property name="jpaDialect"> <bean class="com.company.util.HibernateExtendedJpaDialect" /> </property>