Mantis - Resin
Viewing Issue Advanced Details
1576 major always 01-21-07 11:19 04-12-07 20:27
bregnvig  
westrupp  
normal  
closed 3.1.1  
fixed  
none    
none 3.1.1  
0001576: @OneTOMany and Inheritance problem
I'm going through your Amber tutorial. Works like a charm. I decide to play a bit with it so I expanded the “course” table with a discriminator column and another column called “formula”.

I introduce a new class called RaceCourse, which extends from the Course class. With the following annotations:

Course:
@Entity
@Table(name = "amber_basic_course")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="discriminator", discriminatorType=DiscriminatorType.STRING)
@DiscriminatorValue(value = "course")

RaceCourse:
@Entity
@DiscriminatorValue(value="race")

It works perfectly. So I create a class and table called participant. And a ManyToOne relation from the participant to the table:

@ManyToOne@JoinColumn(name="course_id", nullable=false)
public Course getCourse() {
    return course;
}

Course_id is a foreign key to the course table. This also works perfectly.

Finally I introduce the @OneToMany in the Course class:

@OneToMany(cascade=CascadeType.ALL, mappedBy="course")
public Set<Participant> getParticipants() {
return participants;
}

I can get the participants from the courses. No problem. The problem is the RaceCourse is no longer loaded properly (I use annotation on the properties not the fields). The setter methods for teacher, and formula are no longer called. Removing the getParticipants and setParticipants methods from the course class makes it all work perfectly again.

To me it seems like there is a problem with one to many and inheritance. I can reproduce this every time. I have attached the code if you would like to look at it.

Notes
(0001841)
westrupp   
04-12-07 20:27   
jpa/0l4c