JPQL(Hibernateを使用)で少し苦労しています。
私は2つのエンティティを持っています:
package org.oscarehr.common.model;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.OneToMany;
import javax.persistence.PrePersist;
import javax.persistence.JoinColumn;
import javax.persistence.CascadeType;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
@Entity
@Table(name="spireAccessionNumberMap")
public class SpireAccessionNumberMap extends AbstractModel<Integer> {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(name="uaccn")
private Integer uaccn;
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
@JoinColumn(name="uaccn_id", referencedColumnName="id")
private List<SpireCommonAccessionNumber> commonAccessionNumbers = new ArrayList<SpireCommonAccessionNumber>();
public SpireAccessionNumberMap() {
}
public SpireAccessionNumberMap(Integer uniqueAccn) {
this.uaccn = uniqueAccn;
}
//@Override
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getUniqueAccessionNumber() {
return uaccn;
}
public void setUniqueAccessionNumber(Integer uaccn) {
this.uaccn = uaccn;
}
public List<SpireCommonAccessionNumber> getCommonAccessionNumbers() {
return commonAccessionNumbers;
}
@PrePersist
public void prePersist() {
Iterator<SpireCommonAccessionNumber> i = this.commonAccessionNumbers.iterator();
SpireCommonAccessionNumber commonAccessionNumber;
while(i.hasNext()) {
commonAccessionNumber = i.next();
commonAccessionNumber.setUniqueAccessionId(this.uaccn);
}
}
}
と
package org.oscarehr.common.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
@Entity
@Table(name="spireCommonAccessionNumber")
public class SpireCommonAccessionNumber extends AbstractModel<Integer> {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(name="caccn")
private String caccn;
@ManyToOne
@JoinColumn(name="uaccn_id", referencedColumnName="id")
private Integer uaccn_id;
//@Override
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getCommonAccessionNumber() {
return caccn;
}
public void setCommonAccessionNumber(String caccn) {
this.caccn = caccn;
}
public Integer getUniqueAccessionId() {
return uaccn_id;
}
public void setUniqueAccessionId(Integer uaccn_id) {
this.uaccn_id = uaccn_id;
}
}
基本的に、一意の番号が関連付けられた「マップ」オブジェクトがあります。マップ オブジェクトには、「共通」番号を格納する 1 つ以上の「commonNumber」オブジェクトへの「リンク」があります。
アイデアは、JPQL と 'Dao's を使用して、多くの一般的な番号を一意の番号にマップできるようにすることです。
ただし、Java WAR ファイルをデプロイすると、次のエラーが発生します。
2013-01-04 13:42:12,344 INFO [Version:14] Hibernate Commons Annotations 3.1.0.GA
2013-01-04 13:42:12,347 INFO [Version:16] Hibernate EntityManager 3.4.0.GA
2013-01-04 13:42:17,753 ERROR [ContextLoader:215] Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [spring_jpa.xml]: Invocati
on of init method failed; nested exception is org.hibernate.AnnotationException: @OneToOne or @ManyToOne on org.oscarehr.common.model.SpireCommonAccessionNumber.uaccn_
id references an unknown entity: java.lang.Integer
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:567)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at org.oscarehr.common.web.OscarSpringContextLoader.createWebApplicationContext(OscarSpringContextLoader.java:97)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:943)
at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:778)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:504)
at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1385)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:306)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1389)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1653)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1662)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1642)
at java.lang.Thread.run(Thread.java:679)
Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on org.oscarehr.common.model.SpireCommonAccessionNumber.uaccn_id references an unknown entity: java.lang.Integer
at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:81)
at org.hibernate.cfg.AnnotationConfiguration.processEndOfQueue(AnnotationConfiguration.java:456)
at org.hibernate.cfg.AnnotationConfiguration.processFkSecondPassInOrder(AnnotationConfiguration.java:438)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:309)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1148)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1226)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:173)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:854)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:425)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:131)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:257)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
... 28 more
ここで少し途方に暮れています...「共通」オブジェクトを「マップ」オブジェクトにマップするさまざまな方法をいじってみましたが、エラーが発生し続けます。
誰かが私のためにこれに光を当てることができますか?