编程语言
首页 > 编程语言> > java-无法识别Eclipselink实体

java-无法识别Eclipselink实体

作者:互联网

我有可能依赖其他版本的版本.从属版本存储在列表DependOn中.因为我需要确定在哪个其他版本中使用了特定版本,所以我使用了usedIn列表,它与dependsOn相反.

我的问题是,一旦我添加了用于从dependsOn添加/删除单个Version的方法,EclipseLink便不再将我的类Version识别为实体.

我的版本课程:

@Entity
@Table( name = "tbl_version" )
@NamedQueries( /*...*/ )
public class Version extends BaseEntity
{
    @ManyToMany
    @JoinTable( name = "tbl_depends_on",
        joinColumns = { @JoinColumn( name = "PK_VERSION" ) },
        inverseJoinColumns = { @JoinColumn( name = "PK_DEPENDENCY" ) }
    )
    private List<Version> dependsOn;

    @ManyToMany( mappedBy = "dependsOn" )
    private List<Version> usedIn;

    public void addDependency( Version dependency )
    {
        if( dependency == null )
        {
            return;
        }
        dependsOn.forEach( ( Version version) -> 
        {
            if( dependency.equals( version ) )
            {
                return;
            }
        } );
        dependsOn.add( dependency );
    }

    public void removeDependency( Version dependency )
    {
        if( dependency == null )
        {
            return;
        }
        dependsOn.forEach( ( Version version ) ->
        {
            if( dependency.equals( version ) )
            {
                dependsOn.remove( version );
                return;
            }
        } );
    }
}

一旦删除addDependency和removeDependency,EclipseLink就会再次完美运行.也不是usedIn字段,我已经尝试删除它.
我正在使用EclipseLink 2.5作为持久性api.
有谁知道我在做什么错?

更新资料
抛出以下异常

java.lang.IllegalArgumentException: Object: Version [id=null, 

name=1.2.5] is not a known entity type.
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNewObjectForPersist(UnitOfWorkImpl.java:4222)
    at org.eclipse.persistence.internal.jpa.EntityManagerImpl.persist(EntityManagerImpl.java:496)
    at persistence.VersionTest.setUp(VersionTest.java:71)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

第71行是JUnit测试中的setUp的一部分:

@Before
public void setUp() throws Exception
{
    Version version1 = new Version();
    version1.setName( versionName1 );

    Version version2 = new Version();
    version2.setName( versionName2 );

    EntityTransaction transaction = manager.getTransaction();
    try
    {
        transaction.begin();
        manager.persist( lVersion1 ); //line 71
        //...

解决方法:

如果要在实体代码中使用Java 8 lambda,则应具有与Java 8字节码兼容的EclipseLink的最新版本,否则可能会发生冲突.使用EclipseLink 2.6.0或更高版本.

可以在此错误报告中阅读问题的根源,该错误报告已在2.6.0中解决:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=429992

标签:persistence,eclipselink,java
来源: https://codeday.me/bug/20191027/1948437.html