-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Mapping a List property: unknown target entity property
PostPosted: Wed May 09, 2007 11:30 am 
Newbie

Joined: Wed May 09, 2007 10:36 am
Posts: 4
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 10g


Hello
-------

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.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 10, 2007 5:01 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
I think what's happened is you've not mapped your base classes as @MappedSuperclass. JPA will ignore those properties if you don't specify those classes as such:

http://java.sun.com/javaee/5/docs/api/j ... class.html

I will admit I did not test this but you do have subclasses and I don't see this annotation anywhere :)

-Chris

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 04, 2007 7:03 am 
Newbie

Joined: Mon Nov 26, 2007 12:49 pm
Posts: 7
Chris,

I've more or less the same problem: using inheritance and OneToMany associations mapped on an inherited property.

I tried to put the @MappedSuperclass annotation to the base class but then when I tried to run the test suite of my Ejbs I got the following error:
Code:
java.lang.AssertionError
        at org.hibernate.cfg.AnnotationBinder.getElementsToProcess(AnnotationBinder.java:795)
        at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:645)
        at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:498)
        at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:277)
        at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1115)
        at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1269)
        at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:150)
        at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:888)
        at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:416)
        at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:126)
...


So I tried to remove the @Entity of the base class but then It does not load my @NamedQueries anymore.

So how to deal with generic named queries + inheritance + OneToMany associations?


Code:
@Entity  // ? does not work with MappedSuperclass
@NamedQueries( {
    @NamedQuery(name = "getBadStatus", query = "from Base b where b.status < 1 ORDER BY status")
})
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@MappedSuperclass
public abstract class Base implements java.io.Serializable {
   private long id;
   private Base parent;
   private short status;
 
   @Id
   @Column(name = "`ID`", unique = true, nullable = false, insertable = true, updatable = true)
   @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "base_id_seq_generator")
   @SequenceGenerator(name = "base_id_seq_generator", sequenceName = "base_id_seq", allocationSize = 1)
   public long getId() {
      return this.id;
   }

   public void setId(long id) {
      this.id = id;
   }
 
   @ManyToOne(cascade = {}, fetch = FetchType.LAZY)
   @JoinColumn(name = "`ParentID`", unique = false, nullable = true, insertable = true, updatable = true)
   public Base getParent() {
      return this.parent;
   }

   public void setParent(Base parent) {
      this.parent = parent;
   }

   public short getStatus() {
      return this.status;
   }

   /**
    * @param sendStatus
    */
   public void setSendStatus(short status) {
      this.status = status;
   }
}



/Benoit


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.