Hibernate version: 3.2.2.ga
Full stack trace of any exception that occurs: Code:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateSessionFactory' defined in class path resource [DAOConfig.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: *.data.classifier.BaseMessageCategory.owner in *.data.BaseMessage.categories
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
.initializeBean(AbstractAutowireCapableBeanFactory.java:1088)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
.createBean(AbstractAutowireCapableBeanFactory.java:429)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:250)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry
.getSingleton(DefaultSingletonBeanRegistry.java:141)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:247)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:161)
at org.springframework.beans.factory.support.DefaultListableBeanFactory
.preInstantiateSingletons(DefaultListableBeanFactory.java:270)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:346)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:92)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:77)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:67)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:521)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:84)
... 164 more
Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: *.data.classifier.BaseMessageCategory.owner in *.data.BaseMessage.categories
at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:543)
at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:508)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:43)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1130)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:296)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1286)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:804)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:744)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:131)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1118)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
.initializeBean(AbstractAutowireCapableBeanFactory.java:1085)
... 178 more
Name and version of the database you are using: Oracle 10gHello-------
I have problem with mapping a List property in my entity bean.
I get exception:
Code:
org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: mypackage1.BaseMessageCategory.owner in mypackage2.BaseMessage.categories
at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:543)
at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:508)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:43)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1130)
...
Here is the code of java classes:
Code:
///////// One-To-Many side ////////////////
/* BaseMessage Class */
@Entity
@Table(name = "BASEMESSAGE")
@Inheritance(strategy = InheritanceType.JOINED)
@PrimaryKeyJoinColumn(name = "BASEMESSAGE_ID", referencedColumnName = "BASEOBJECT_ID")
public class BaseMessage extends BaseObject {
/** List of content category classificators - the list I want to map!*/
@OneToMany(cascade = CascadeType.ALL, mappedBy = SirClassifier.OWNER_ATTR,
targetEntity = BaseMessageCategory.class)
private List<BaseMessageCategory> categories;
//... setters getters and other not important stuff ...
}
/* BaseObject class */
@Entity
@Table(name = "BASEOBJECT")
@Inheritance(strategy = InheritanceType.JOINED)
@PrimaryKeyJoinColumn(name = "BASEOBJECT_ID", referencedColumnName = "ID")
public abstract class BaseObject extends ClassifierOwner {
// ... not important stuff ...
}
/* ClassifierOwner class */
@Entity
@Table(name = "CLASSIFIEROWNER")
@Inheritance(strategy = InheritanceType.JOINED)
@SequenceGenerator(name = "ID_SEQ", sequenceName = "ID_SEQ")
public abstract class ClassifierOwner implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ID_SEQ")
private Long id;
// ... setters getters and other not important stuff ...
}
///////// Many-To-One side ////////////////
/* BaseMessageCategory class */
@Entity
@DiscriminatorValue(BaseMessageCategory.DISCR)
@Where(clause = SirClassifier.DISCR_FIELD + "='" + BaseMessageCategory.DISCR + "'")
public class BaseMessageCategory extends SirClassifier {
public static final String DISCR = "BaseMessageCategory";
public BaseMessageCategory() {
super();
}
public BaseMessageCategory(String code) {
super(code, ClassifierName.ContentCategory);
}
}
/* SirClassifier class */
@Entity
@Table(name = "CLASSIFIER")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name=SirClassifier.DISCR_FIELD, discriminatorType=DiscriminatorType.STRING, length=40)
@SequenceGenerator(name="ID_SEQ", sequenceName="ID_SEQ")
public abstract class SirClassifier implements Serializable {
private static final long serialVersionUID = 1L;
public static final String OWNER_ATTR = "owner";
public static final String DISCR_FIELD = "DISCR";
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ID_SEQ")
private Long id;
@ManyToOne(targetEntity = ClassifierOwner.class)
@JoinColumn(name = "OWNERID")
private ClassifierOwner owner;
@Column
@Enumerated(EnumType.STRING)
private ClassifierName className;
@Column
private String code;
// ...
}
So basicly there are two types of inheritence here:
1. The one-to-many side, BaseMessage uses InheritanceType.JOINED, meaning every class has its own database table.
2. The many-to-one side, BaseMessageCategory and other classes who extend the SirClassifier base class are useing InheritanceType.SINGLE_TABLE, so that all the child entitys (classifiers) are stored in one database table.
I also give short description about the database tables:
Code:
CLASSIFIEROWNER(ID)
BASEOBJECT(BASEOBJECT_ID)
BASEMESSAGE(BASEMESSAGE_ID)
CLASSIFIER(ID, DISCR, OWNERID, CODE, CLASSNAME)
I would be very thankfull if somebody could look through my BaseMessage class and BaseMessageCategory class, the part where I have annotated the many-to-one relationship. In my opinion I have done everything by the book, but the cryptic hibernate exception really does not help me.
Jux.