-->
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.  [ 5 posts ] 
Author Message
 Post subject: Unknown mappedBy in Problem with PrimaryKeyJoinColumn
PostPosted: Tue Sep 23, 2008 7:15 am 
Newbie

Joined: Tue Oct 02, 2007 3:49 am
Posts: 17
Dear All,

I got a problem on one-to-one mapping in a PrimaryKeyJoinColumn entity. An annotation error is shown like "unknown mapped by". My entity is inheritance from a base class Resource with strategy in single table. Each book may bundle with an unique cd. Thus I mapped with CdDisc class in One to one mapping

Code:
@Entity
@Table(name = "book")
@DiscriminatorValue("book")
@PrimaryKeyJoinColumn(name = "id")
public class Book extends Resource {

   @OneToOne(optional = true)
   @JoinColumn(name = "cd_nbr")
   private CdDisc cd;

....


Code:
@Entity
@Table(name = "cd_disc")
public class CdDisc extends ModelBase {
   @Id
   @Column(name = "cd_nbr", nullable = false, unique = true)
   private String cdNbr = "";

   @OneToOne(mappedBy = "cd")
   private Book book;
....


I think my syntax should be correct and I also have some other one to one mapping doing same like this. Only diff is one of entity is using PrimaryKeyJoinColumn to do. I'm greatly appreciate for any suggestion or idea to me. Thanks

Best Rdgs
Ellis


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 23, 2008 8:52 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi Ellis,

could you post the full stack trace please? Also, why do you use @PrimaryKeyJoinColumn(name = "id")? This annotations is normally used when using joined subclasses, however you are using the table per class hierachy strategy.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 23, 2008 10:08 pm 
Newbie

Joined: Tue Oct 02, 2007 3:49 am
Posts: 17
Hardy,

Thanks for your reply. Sorry for my typing mistake. You're right it should be inheritance by Joined. Reason of using @PrimaryKeyJoinColumn is I want to have a same shared primary key along its inheritance with parent class also. For example, if the id of record in class Resource is "0100", I also want its id in corresponding record in subclass "Book" same as "0100". Do I use the @PrimaryKeyJoinColumn correctly? Below is my detail stack log



Code:
Caused by: org.hibernate.AnnotationException: Unknown mappedBy in: com.model.CdDisc.book, referenced property unknown: com.model.Book.cd
   at org.hibernate.cfg.OneToOneSecondPass.doSecondPass(OneToOneSecondPass.java:129)
   at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1136)
   at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:324)
   at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1121)
   at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1225)
   at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:159)
   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:224)
   at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:291)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1368)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1334)
   ... 28 more


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 24, 2008 4:08 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

I still think that you don't need the @PrimaryKeyJoinColumn. The behaviour you describe should be the default. You also should not need @DiscriminatorValue. That's intended for use in table per class hierachy.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 24, 2008 5:41 am 
Newbie

Joined: Tue Oct 02, 2007 3:49 am
Posts: 17
Hardy

Reason using @DiscriminatorValue is other than class "Book", I also have some other resources like "Racket" etc.. thus, in my class "Resources", I use a DiscriminatorColumn "Type" to classify each type of resources.

And about the @PrimaryKeyJoinColumn, if I didn't use it, will the primary key in class "Book" and "Resource" are shared the same?

Best Rdgs
Ellis


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.