Java 多个项目中的实体
我有一个Spring项目,效果很好。我现在需要将项目分成两部分-主要是因为在另一个项目中使用现有项目的部分。当我分手时,我面临着一个问题,我不明白,也不知道问题的根源是什么。例如Java 多个项目中的实体,java,spring,eclipselink,Java,Spring,Eclipselink,我有一个Spring项目,效果很好。我现在需要将项目分成两部分-主要是因为在另一个项目中使用现有项目的部分。当我分手时,我面临着一个问题,我不明白,也不知道问题的根源是什么。例如 + -- myTestProject | -- PersonEntity | -- persistence.xml | -- pom.xml + -- myBaseProject | | -- PhoneEntity | -- pom.xml 当我将PhoneEntity保存在myTestPr
+ -- myTestProject
| -- PersonEntity
| -- persistence.xml
| -- pom.xml
+ -- myBaseProject
|
| -- PhoneEntity
| -- pom.xml
当我将PhoneEntity保存在myTestProject
中时,我可以毫无问题地启动Tomcat。当我像上面那样分离实体时,我从EclipseLink
得到错误消息:
实体类[class com.smith.Company]上的属性[PhoneEntity]的类型[class com.smith.PhoneEntity]不是序列化映射的有效类型。属性类型必须实现可序列化接口。
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="eclipselink" transaction-type="RESOURCE_LOCAL">
<description>Application managed persistence unit</description>
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<non-jta-data-source>java:comp/env/jdbc/ecoiDS</non-jta-data-source>
<class>com.smith.PersonEntity</class>
<class>com.smith.PhoneEntity</class>
<class>com.smith.Company</class>
<properties>
<property name="eclipselink.logging.level" value="WARNING" />
<property name="eclipselink.logging.timestamp" value="true" />
<property name="eclipselink.logging.session" value="false" />
<property name="eclipselink.logging.thread" value="false" />
<property name="eclipselink.logging.exceptions" value="true" />
<property name="eclipselink.weaving" value="static"/>
<property name=""/>
</properties>
</persistence-unit>
</persistence>
应用程序管理持久化单元
org.eclipse.persistence.jpa.PersistenceProvider
java:comp/env/jdbc/ecoiDS
人格
com.smith.PhoneEntity
史密斯公司
persistence.xml
也包含了PhoneEntity
。整个项目编制得很好。但不知何故,我无法启动该项目。有没有解决问题的提示?您正在尝试
我建议:您创建第三个模块,在其中添加所有实体以及persistence.xml
文件,然后在Base
和Test
模块中添加该模块的依赖项
您可以在这里找到一个实际的例子->。您应该展示
persistence.xml
的相关部分。答案可能就在那里。更新为persistence.xml
“将项目分成两部分”您所说的“部分”是什么意思?如果您指的是模块,那么您可以为jpa类创建第三个模块,包括实体和persistence.xmlByModules
您指的是Java9-Modules
?或者你是什么意思<代码>分为两部分意味着我有一个应该仍然运行的现有项目。而不是将一些基础划分到一个基础项目中——可以在另一个项目中重用。这会导致一些实体属于基础项目,而其他实体则不属于基础项目。但最重要的是,我不知道Eclipselink在抱怨什么。由于所有实体都在persistence.xml
thanx中提到,请检查我刚才在回答中所写的内容。因此您的意思是有一个EntityProject
,它由所有实体组成,聚集在persistence.xml
中。因此,例如,JPARepro
来到Base
项目。这些我可以在测试项目中使用-只需添加依赖项?我是否正确理解了pom.xml
中的主要差异是
属性?就在
中,我喜欢遵循我在回答中提到的Spring tutrial,只需^30分钟,您就可以从maven;)了解如何管理项目