我有两个实体,其中一个继承了另一个,所以我在 jar1 中有 entity1 并且我有一个 jar2 entity2->inherits(entity1)
在 jar1 中:
@Entity
public class Entity1 {...}
在 jar2 中:
@Entity
public class Entity2 extends Entity1 {...}
那么我怎样才能让它工作,它甚至没有编译说:
An annotation processor threw an uncaught exception...
Caused by: java.lang.NullPointerException
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor.discoverMappedSuperclassesAndInheritanceParents(EntityAccessor.java:224)
看似简单,但行不通,怎么办?
更新:
这是 jar2 的 persistencel.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns /persistence/persistence_2_0.xsd">
<persistence-unit name="EntityBPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>my_datasource</jta-data-source>
<jar-file>jar1.jar</jar-file>
<properties>
<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
</properties>
</persistence-unit>
最佳答案
理论上,在不同的 JAR 中有两个相关实体没有什么特别之处。
检查您的环境和编译方式。
关于java - 当继承跨不同的 JAR 时如何使用 @Entity 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8372175/