使用IntegrityException弹出eclipselink问题

时间:2011-06-08 22:21:34

标签: spring jpa eclipselink

我尝试将spring与eclipseLink一起使用,并且我遇到了IntegrityException。 这是我的配置:

<?xml version="1.0" encoding="UTF-8"?>

xsi:schemaLocation="http://www.springframework.org/schema/beans 
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

<import resource="data-source.xml" />

<tx:annotation-driven mode="proxy"
    transaction-manager="transactionManager" />

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
    p:entityManagerFactory-ref="entityManagerFactory" />

<!-- Entity manager -->
<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="persistenceUnitName" value="unit1" />
    <property name="loadTimeWeaver">
        <bean class="org.springframework.instrument.classloading.SimpleLoadTimeWeaver"/>
    </property>
    <property name="jpaVendorAdapter">
        <bean
            class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
            <property name="databasePlatform" value="org.eclipse.persistence.platform.database.DerbyPlatform" />
            <property name="showSql" value="true" />
            <property name="generateDdl" value="true" />
        </bean>
        <!-- <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> -->
        <!-- <property name="databasePlatform" value="org.hibernate.dialect.DerbyDialect" 
            /> -->
        <!-- <property name="showSql" value="true" /> -->
        <!-- <property name="generateDdl" value="true" /> -->
        <!-- </bean> -->
    </property>
</bean>

<bean id="jpaTemplate" class="org.springframework.orm.jpa.JpaTemplate">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

完全例外是:

[EL Config]:2011-06-09 00:15:24.061 - ServerSession(2050312009) - 连接(473155160) - 线程(线程[main,5,main]) - 已连接:jdbc:derby ://本地主机:1527 / springhib;创建=真     用户:app     数据库:Apache Derby版本:10.6.2.1 - (999685)     驱动程序:Apache Derby网络客户端JDBC驱动程序版本:10.7.1.1 - (1040133) [EL Severe]:2011-06-09 00:15:24.127 - ServerSession(2050312009) - 线程(线程[main,5,main]) - 本地异常堆栈: 异常[EclipseLink-0](Eclipse Persistence Services - 2.2.0.v20110202-r8913):org.eclipse.persistence.exceptions.IntegrityException 描述符例外:

异常[EclipseLink-148](Eclipse Persistence Services - 2.2.0.v20110202-r8913):org.eclipse.persistence.exceptions.DescriptorException 异常描述:容器策略[CollectionContainerPolicy(类org.eclipse.persistence.indirection.IndirectSet)]与透明间接不兼容。 映射:org.eclipse.persistence.mappings.ManyToManyMapping [comments] 描述符:RelationalDescriptor(pl.adaknet.hibspring.domain.ArtEntity - &gt; [DatabaseTable(ARTENTITY)])

但是当我使用其他供应商时我没有这个问题

org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter

任何想法?

3 个答案:

答案 0 :(得分:2)

尝试使用此loadtimeweaver实现:

package net.palesz.util;

import org.springframework.instrument.classloading.SimpleLoadTimeWeaver;

public class JpaAwareLoadTimeWeaver extends SimpleLoadTimeWeaver {
    @Override
    public ClassLoader getInstrumentableClassLoader() {
        ClassLoader instrumentableClassLoader = super.getInstrumentableClassLoader();
        if (instrumentableClassLoader.getClass().getName().endsWith("SimpleInstrumentableClassLoader")) {
            return instrumentableClassLoader.getParent();
        } else {
            return instrumentableClassLoader;
        }
    }
}

Spring context.xml config:

<bean id="loadTimeWeaver" class="net.palesz.util.JpaAwareLoadTimeWeaver" />

答案 1 :(得分:0)

奇怪的错误,因为IndirectSet有效。它似乎是一个类加载器问题,但我之前没有在Spring中看到它。

它可能与您使用loadTimeWeaver有关,因此您可以尝试删除它。

你在什么环境下运行Spring?

答案 2 :(得分:0)

你必须使用代理进行动态编织 -javaagent:弹簧剂2.5.6.jar
我曾尝试过eclipseLink代理,但它没有用。

关于在春天编织JPA的更多信息:
http://docs.spring.io/spring/docs/3.0.0.M3/reference/html/ch14s06.html
如果你想在tomcat上运行你的代码:
http://docs.spring.io/spring/docs/3.0.0.M3/reference/html/ch14s06.html#orm-jpa-setup-lcemfb-tomcat