开发者

spring eclipselink problem with IntegrityException

I try to use spring with eclipseLink and I've got an IntegrityException. This is my configuration:

<?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">开发者_如何学Python; -->
        <!-- <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>

and exactly exception is:

[EL Config]: 2011-06-09 00:15:24.061--ServerSession(2050312009)--Connection(473155160)--Thread(Thread[main,5,main])--Connected: jdbc:derby://localhost:1527/springhib;create=true User: app Database: Apache Derby Version: 10.6.2.1 - (999685) Driver: Apache Derby Network Client JDBC Driver Version: 10.7.1.1 - (1040133) [EL Severe]: 2011-06-09 00:15:24.127--ServerSession(2050312009)--Thread(Thread[main,5,main])--Local Exception Stack: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.IntegrityException Descriptor Exceptions:

Exception [EclipseLink-148] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.DescriptorException Exception Description: The container policy [CollectionContainerPolicy(class org.eclipse.persistence.indirection.IndirectSet)] is not compatible with transparent indirection. Mapping: org.eclipse.persistence.mappings.ManyToManyMapping[comments] Descriptor: RelationalDescriptor(pl.adaknet.hibspring.domain.ArtEntity --> [DatabaseTable(ARTENTITY)])

but i don't have this problem when I use another Vendor

org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter

any ideas?


Try to use this loadtimeweaver implementation:

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" />


An odd error because IndirectSet is valid. It seems to be a class loader issue, but I have not seen this in Spring before.

It could be related to your usage of loadTimeWeaver, so you could try removing that.

In what environment are you running Spring?


you have to use agent for dynamic weaving
-javaagent:spring-agent-2.5.6.jar
i had tried eclipseLink agent, but it didn't work.

more info about weaving for JPA on Spring:
http://docs.spring.io/spring/docs/3.0.0.M3/reference/html/ch14s06.html
if you would like run your code on tomcat:
http://docs.spring.io/spring/docs/3.0.0.M3/reference/html/ch14s06.html#orm-jpa-setup-lcemfb-tomcat

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜