-->
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.  [ 4 posts ] 
Author Message
 Post subject: Inheritance on Associations
PostPosted: Wed Feb 24, 2010 8:45 am 
Newbie

Joined: Wed Feb 24, 2010 8:23 am
Posts: 2
  • I use a class Set and a separate class IndexedSet.
  • Set has an association implemented by SetAssignment.
  • IndexedSet has an association implemented by IndexedSetAssignment, which is a child class of SetAssignment
  • Both SetAssignment and IndexedSetAssignment use @EmbeddedIDs implemented by the classes SetAssignmentId and IndexedSetAssignmentId (the latter as a child of the first).
  • The examples, of course, show only fragments of the real structure :-)

The following error arises on "mvn hibernate3:hbm2ddl":
org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: IndexedSetAssignment.set in IndexedSet.assignments

I do not understand why:
IndexedSet.assignments referenced to IndexedSetAssignment.set, although "set" is inherited by its father class SetAssignment. Why does hibernate not use the propertiy of its father class?

Can you help me?


Code:
@Entity
class Set implements Serializable {
  @OneToMany(mappedBy="set")
  @MapKey
  Map<SetAssignmentId, SetAssignment> setassignments;
  (...)
}

@Entity
class IndexedSet implements Serializable {
  @OneToMany(mappedBy="set")
  @OrderBy("index")
  List<IndexedSetAssignment> setassignments;
  (...)
}

@Entity
class SetAssignment implements Serializable {
  @EmbeddedId
  private SetAssignmentId id;

  @ManyToOne
  @JoinColumn(name="set", insertable = false, updatable = false, nullable = false)
  private Set set;
  (...)
}

@Embeddable
class SetAssignmentId implements Serializable {
  private Long set;
  (...)
}

@Entity
class IndexedSetAssignment extends SetAssignment implements Serializable {
  @Column(name="index", insertable=false, updatable=false, nullable=true)
  private int index;
  (...)
}

@Embeddable
class IndexedSetAssignmentId extends SetAssignmentId implements Serializable {
  private Integer index;
  (...)
}


Top
 Profile  
 
 Post subject: Re: Inheritance on Associations
PostPosted: Wed Feb 24, 2010 12:20 pm 
Beginner
Beginner

Joined: Tue Aug 25, 2009 11:42 am
Posts: 49
Can u first try not to use the name "Set" but maybe use a different class name "SonnySet" for instance?
And then how would Hibernate know that IndexedSetAssignment is a subclass of SetAssignment? I think there is no default strategy thus u have to make use of @Inheritance with the parent class, viz. SetAssignment.
See http://docs.jboss.org/hibernate/stable/ ... le/#d0e829

For u u are probably happiest with
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class SetAssignment


Top
 Profile  
 
 Post subject: Re: Inheritance on Associations
PostPosted: Wed Feb 24, 2010 12:28 pm 
Newbie

Joined: Wed Feb 24, 2010 8:23 am
Posts: 2
Thank you for your reply!

Ok, "Set" was stupid renaming when changing the things to present them here. In reality "Set" has a different name and will - for sure - not be mixed up with java.util.Set.

I tried to add @Inheritance to the super class - with no effect on the error.


Top
 Profile  
 
 Post subject: Re: Inheritance on Associations
PostPosted: Wed Feb 24, 2010 1:57 pm 
Beginner
Beginner

Joined: Tue Aug 25, 2009 11:42 am
Posts: 49
The SetAssignmet says that it's "parent" is a Set (your Set not the java.util.Set)
But when we come to IndexedSetAssignment, we should have "IndexedSet" as the parent and u have no inheritance hierarchy between Set and IndexedSet.
Does that explain?
However, if u establish such a relation than you will be overwriting the map field with a list field.
Convoluted!


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