-->
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.  [ 2 posts ] 
Author Message
 Post subject: problem with inheriting foreign key property
PostPosted: Wed Jan 21, 2009 6:44 am 
Newbie

Joined: Wed Jan 21, 2009 6:25 am
Posts: 1
Location: Poland
I've got a problem with inheriting a foreign key. I've got three classes:
Code:
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
class Disc{
  @Id @GeneratedValue
  long id;
  @ManyToOne
  DiscCollection coll;
}

@Entity
class AudioDisc extends Disc{}

@Entity
class DiscCollection{
@Id @GeneratedValue
  long id;
  @OneToMany(mappedBy="coll")
  List<Disc> discs = new ArrayList<Disc>();
}

Everything is OK here. However, if I change List generic type in the last class to:
Code:
  List<AudioDisc> discs = new ArrayList<AudioDisc>();

then i get the following exception:
Code:
Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: tests.AudioDisc.coll in tests.DiscCollection.discs
   at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:552)
   at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:517)
   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:316)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1286)
   at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915)

It looks like hibernate can't see that AudioDisc class inherits coll property from its Disc superclass. I can't find such example or any solution in the Manning book.

Regards,
czarek_r


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2009 8:31 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Your mapping is kind of inconsistent if you change your type. Any Disc can belong to a DiscCollection, but a DiscCollection only consists of AudioDiscs? Thats not logical, so hibernate does not support it.

It's like defining a vehicle which can be parked in a building, but also saying that this building can only contain bicycles (which are vehicles).

_________________
-----------------
Need advanced help? http://www.viada.eu


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