使用EclipseLinkJpaDialect在Spring中将PersistenceException转换为DataAccessException

时间:2011-06-03 09:44:13

标签: spring exception translation eclipselink data-access

喂。 我有同样的问题解释here

主要区别在于我使用EclipseLink作为JpaProvider。 所以我将entityManagerFactory配置如下:

<bean id="entityManagerFactoryCont0" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceXmlLocation" value="classpath:META-INF/contratto-persistence-cont0.xml" />
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter"/>
    </property>
    <property name="jpaDialect">
        <bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect" />
    </property>
</bean> 

我注意到EclipseLink没有覆盖DefaultJpaDialect类的translateExceptionIfPossible方法,这很糟糕......

所以在我的测试用例中我有一个唯一的约束违例异常,调试控制流程显示了这个堆栈跟踪:

EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(RuntimeException) line: 282   
EclipseLinkJpaDialect(DefaultJpaDialect).translateExceptionIfPossible(RuntimeException) line: 120   
LocalContainerEntityManagerFactoryBean(AbstractEntityManagerFactoryBean).translateExceptionIfPossible(RuntimeException) line: 368   
ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(RuntimeException) line: 58   
DataAccessUtils.translateIfNecessary(RuntimeException, PersistenceExceptionTranslator) line: 213    
PersistenceExceptionTranslationInterceptor.invoke(MethodInvocation) line: 163   
ReflectiveMethodInvocation.proceed() line: 172

电话的例外是:

javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.1.2.v20101206-r8635): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: [BEA][Oracle JDBC Driver][Oracle]ORA-00001: unique constraint (JSP_OWN.IDX_MC_CC_RAPPORTI_02) violated

返回的最后一个异常是一般的JpaSystemException:

org.springframework.orm.jpa.JpaSystemException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.1.2.v20101206-r8635): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLIntegrityConstraintViolationException: ORA-00001: violata restrizione di unicità (CONT_OWN.PK_CONT_EVENT_MESSAGE)

知道如何让机器适用于EclipseLink吗? 亲切的问候

的Massimo

0 个答案:

没有答案