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