当继承跨越单独的JAR时,如何使用@Entity属性? [英] How to use @Entity attribute when inheritance is across separate JARs?

查看:101
本文介绍了当继承跨越单独的JAR时,如何使用@Entity属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个实体,其中一个继承了另一个实体,因此我在 jar1 entity1 中,而我又有一个 jar2 entity2->继承(entity1)

I have two entities where one of them inherits the other one, so I have in jar1 the entity1 and I have a jar2 the entity2->inherits(entity1)

在jar1中:

@Entity
public class Entity1 {...}

在jar2中:

@Entity
public class Entity2 extends Entity1 {...}

所以我该如何工作,它甚至没有编译为:

So how can I make this to work, it doesn't even compile saying:

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)

看似简单,但不起作用,我该怎么办?

It seems simple, but it does not work, what should I do?

更新:

这是jar2的persistencel.xml:

Here is the persistencel.xml for jar2:

<?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中具有两个相关的实体并没有什么特别的.

Theoretically there's nothing special about having two related entities in different JARs.

检查环境和编译方式.

这篇关于当继承跨越单独的JAR时,如何使用@Entity属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆