我遇到了迁移项目问题。我有一个非常非常古老的java ee项目,目前在jboss 4服务器上运行。我正试图在一个新的apache tomee安装上迁移它。
实体类的编码如下:
@Entity
@Table(name="last_alarm_raised")
public class LastAlarmRaised implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
private LastAlarmRaisedPK id;
PK等级
@Embeddable
public class LastAlarmRaisedPK implements Serializable {
private static final long serialVersionUID = 1L;
@ManyToOne
@JoinColumn(name="unit_id", nullable=false)
private Box box;
@Column(name="alarm_box_number")
private long alarmBoxNumber;
Box class
@Entity
@Table(name="box")
public class Box implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name="unit_id")
private long unitId;
实际上这适用于jboss 4服务器安装但是当我尝试在apache tomee上启动它时,我收到以下错误:
AVERTISSEMENT: An exception was thrown while attempting to perform class file transformation on "org.orphee.gps.beans.entity.Box":
<openjpa-2.3.0-nonfinal-1540826-r422266:1542644 fatal user error> org.apache.openjpa.util.MetaDataException: Errors encountered while resolving metadata. See nested exceptions for details.
at org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.java:675)
at org.apache.openjpa.meta.MetaDataRepository.getMetaDataInternal(MetaDataRepository.java:418)
at org.apache.openjpa.meta.MetaDataRepository.getMetaData(MetaDataRepository.java:389)
at org.apache.openjpa.enhance.PCEnhancer.<init>(PCEnhancer.java:286)
at org.apache.openjpa.enhance.PCEnhancer.<init>(PCEnhancer.java:257)
at org.apache.openjpa.enhance.PCClassFileTransformer.transform0(PCClassFileTransformer.java:146)
at org.apache.openjpa.enhance.PCClassFileTransformer.transform(PCClassFileTransformer.java:126)
at org.apache.openjpa.persistence.PersistenceProviderImpl$ClassTransformerImpl.transform(PersistenceProviderImpl.java:291)
at org.apache.openejb.persistence.PersistenceUnitInfoImpl$PersistenceClassFileTransformer.transform(PersistenceUnitInfoImpl.java:324)
at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:434)
at java.lang.ClassLoader.defineClassImpl(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:306)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:143)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2918)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1174)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1669)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
at org.apache.tomee.catalina.LazyStopWebappClassLoader.loadClass(LazyStopWebappClassLoader.java:109)
at java.lang.Class.getDeclaredMethodsImpl(Native Method)
at java.lang.Class.getDeclaredMethods(Class.java:783)
at java.lang.Class.getInterfaceMethodCountImpl(Class.java:1162)
at java.lang.Class.getInterfaceMethodsImpl(Class.java:1192)
at java.lang.Class.getMethods(Class.java:1075)
at org.apache.openejb.BeanContext.mapObjectInterface(BeanContext.java:1205)
at org.apache.openejb.BeanContext.createMethodMap(BeanContext.java:1083)
at org.apache.openejb.assembler.classic.EnterpriseBeanBuilder.build(EnterpriseBeanBuilder.java:300)
at org.apache.openejb.assembler.classic.EjbJarBuilder.build(EjbJarBuilder.java:65)
at org.apache.openejb.assembler.classic.Assembler.initEjbs(Assembler.java:975)
at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:790)
at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:612)
at org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal(TomcatWebAppBuilder.java:1205)
at org.apache.tomee.catalina.TomcatWebAppBuilder.configureStart(TomcatWebAppBuilder.java:1051)
at org.apache.tomee.catalina.GlobalListenerSupport.lifecycleEvent(GlobalListenerSupport.java:127)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5322)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:781)
Caused by: <openjpa-2.3.0-nonfinal-1540826-r422266:1542644 fatal user error> org.apache.openjpa.util.MetaDataException: The id class specified by type "class org.orphee.gps.beans.entity.LastAlarmRaised" does not match the primary key fields of the class. Make sure your identity class has the same primary keys as your persistent type, including pk field types. Mismatched property: "box"
at org.apache.openjpa.meta.ClassMetaData.validateAppIdClassPKs(ClassMetaData.java:2225)
at org.apache.openjpa.meta.ClassMetaData.validateAppIdClass(ClassMetaData.java:2069)
at org.apache.openjpa.meta.ClassMetaData.validateIdentity(ClassMetaData.java:2035)
at org.apache.openjpa.meta.ClassMetaData.validateMeta(ClassMetaData.java:1947)
at org.apache.openjpa.meta.ClassMetaData.resolve(ClassMetaData.java:1808)
at org.apache.openjpa.meta.MetaDataRepository.processBuffer(MetaDataRepository.java:829)
at org.apache.openjpa.meta.MetaDataRepository.resolveMeta(MetaDataRepository.java:726)
at org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.java:650)
... 44 more
我需要在PK类中保留@ManyToOne关系。有人知道问题是为了帮助我吗?
坦克很多:)
Hello Rick, Ty给你答案。
我尝试更新我的链接中提到的实体(我的第一篇帖子中的实体不同但问题相同):
带有embeddedId的实体
@Entity
@Table(name="account_social_state")
public class AccountSocialState implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
private AccountSocialStatePK id;
@ManyToOne
@JoinColumn(name="account_id")
private Account account;
@ManyToOne
@JoinColumn(name="social_state_id")
private SocialState socialState;
嵌入式课程
@Embeddable
public final class AccountSocialStatePK implements java.io.Serializable {
private static final long serialVersionUID = 0;
@Column(name="account_id", insertable=false, updatable=false, nullable=false)
private int account;
@Column(name="social_state_id", insertable=false, updatable=false, nullable=false)
private int socialState;
和persistence.xml
<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
<persistence-unit name="persistence-unit">
<jta-data-source>unit</jta-data-source>
<properties>
<property name="openjpa.jdbc.SynchronizeMappings" value="validate"/>
<property name="openjpa.Log" value="File=C:\org.apache.openjpa.log, DefaultLevel=TRACE, Runtime=TRACE, Tool=TRACE, SQL=TRACE" />
</properties>
</persistence-unit>
</persistence>
但总是得到这条日志消息:
org.apache.openjpa.persistence.ArgumentException: The id class specified by type "class org.beans.entity.AccountState" does not match the primary key fields of the class. Make sure your identity class has the same primary keys as your persistent type, including pk field types. Mismatched property: "account"
有没有解决办法? Ty!