que estoy recibiendo la excepción abajo en mi aplicación web muelle 3 usando Hibernate 4:referencedColumnNames de hibernación no se asignan a una sola propiedad
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in URL [file:war/WEB-INF/datasource-config.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: referencedColumnNames(DISCUSSION_ID) of com.jr.freedom.discusion.Message.discussion referencing com.jr.freedom.discusion.Discussion not mapped to a single property
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.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:96)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:44)
at org.springframework.test.context.TestContext.buildApplicationContext(TestContext.java:198)
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:233)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:126)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:85)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:231)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:95)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:139)
at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.hibernate.AnnotationException: referencedColumnNames(DISCUSSION_ID) of com.jr.freedom.discusion.Message.discussion referencing com.jr.freedom.discusion.Discussion not mapped to a single property
at org.hibernate.cfg.BinderHelper.createSyntheticPropertyReference(BinderHelper.java:205)
at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:116)
at org.hibernate.cfg.Configuration.processEndOfQueue(Configuration.java:1514)
at org.hibernate.cfg.Configuration.processFkSecondPassInOrder(Configuration.java:1437)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1355)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1724)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1775)
at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:184)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:314)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
... 29 more
A continuación se muestra el POJO mensaje que está utilizando el discission Pojo:
@Entity
@Table(name = "MESSAGE")
public class Message {
@Id
@Column(name = "message_id")
private String id;
@Column(name = "message_text", nullable = false)
private String messageText;
/**
* Foreign key for user table
*/
@Id
@OneToOne
@JoinColumn(name = "from_user", nullable = false)
private User fromUser;
/**
* Foreign key for discussion table
*/
@Id
@ManyToOne
@JoinColumn(name = "discussion",referencedColumnName="DISCUSSION_ID", nullable = false)
private Discussion discussion;
public Message() {
id = UUID.randomUUID().toString();
}
public String getMessageText() {
return messageText;
}
public void setMessageText(String messageText) {
this.messageText = messageText;
}
public User getFromUser() {
return fromUser;
}
public void setFromUser(User fromUser) {
this.fromUser = fromUser;
}
public Discussion getDiscussionId() {
return discussion;
}
public void setDiscussionId(Discussion discussion) {
this.discussion = discussion;
}
public String getId() {
return id;
}
}
Aquí es la discusión POJO:
@Entity
@Table(name = "DISCUSSION")
public class Discussion {
@Id
@Column(name = "DISCUSSION_ID")
private String id;
@Column(name = "TITLE", nullable = false)
private String title;
@Column(name = "CATAGORY", nullable = false)
private String catagory;
@Id
@OneToOne
@JoinColumn(name = "discussionOwner", nullable = false)
private User discussionOwner;
public Discussion() {
id = UUID.randomUUID().toString();
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getCatagory() {
return catagory;
}
public void setCatagory(String catagory) {
this.catagory = catagory;
}
public User getDiscussionOwner() {
return discussionOwner;
}
public void setDiscussionOwner(User discussionOwner) {
this.discussionOwner = discussionOwner;
}
public String getId() {
return id;
}
}
¿Qué me falta? la relación entre estas dos entidades es que una entidad discusión puede contener muchos mensajes y un mensaje sólo puede pertenecer a una discusión
Gracias de antemano
¿Realmente tiene identificaciones compuestas en ambas tablas? Tus asignaciones están por todos lados, y tienes múltiples asignaciones de columnas en blanco en tu objeto de discusión. Publique el DDL para ambas tablas, por favor. – Perception
¿cómo publico DDL para estas tablas? Publicación editada para completar coloumns en blanco – jonney
La ID en ambas entidades debería ser suficiente para identificar de manera única la eneidad. Debería ser el único campo con la anotación @Id. –