无法识别 Eclipselink 实体
Eclipselink Entity is not recognized
我有可能依赖于其他版本的版本。依赖版本存储在列表 dependsOn
中。因为我需要能够确定,在哪些其他版本中使用了特定版本我有列表 usedIn
这是 dependsOn.
的倒数
我的问题是,一旦我将方法添加到 add/remove 来自 dependsOn
的单个版本,EclipseLink 就不再将我的 class Version
识别为实体。
我的版本class:
@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.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.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access[=11=]0(ParentRunner.java:53)
at org.junit.runners.ParentRunner.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 测试中设置的一部分:
@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 中得到解决:
我有可能依赖于其他版本的版本。依赖版本存储在列表 dependsOn
中。因为我需要能够确定,在哪些其他版本中使用了特定版本我有列表 usedIn
这是 dependsOn.
我的问题是,一旦我将方法添加到 add/remove 来自 dependsOn
的单个版本,EclipseLink 就不再将我的 class Version
识别为实体。
我的版本class:
@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.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.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access[=11=]0(ParentRunner.java:53)
at org.junit.runners.ParentRunner.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 测试中设置的一部分:
@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 中得到解决: