Here's a simplified example of what I want to achieve:
I have 3 tables:
Code:
STUDENT {
STUDENT_ID,
NAME
}
HOBBY {
STUDENT_REF,
HOBBY
}
AWARD {
STUDENT_REF,
AWARDS
}
1. STUDENT_REF colums have a foreign key referring to STUDENT_ID column.
2. There is a One-To-Many relationship between STUDENT and HOBBY/AWARD.
The standard way to model this in Java classes is:
Code:
@Entity
class Student {
int id;
String name;
@One-To-Many(...)
Set<Hobby> hobbies;
@One-To-Many(...)
Set<Award> award;
}
@Entity
class Hobby {
...
}
@Entity
class Award {
...
}
However, I want to introduce another containing class - StudentDetails - which does not have a mapping to any table and model it thus:
Code:
@Entity
class Student {
int id;
String name;
StudentDetails details;
}
class StudentDetails {
@One-To-Many(...)
Set<Hobby> hobbies;
@One-To-Many(...)
Set<Award> award;
}
@Entity
class Hobby {
Student student;
...
}
@Entity
class Award {
Student student;
...
}
Note that Hobby and Award classes have a reference back to Student and not to StudentDetails.
How can I achieve this? Should I be using embedded objects? I haven't (yet) figured out how. Any hints will be appreciated and devoured.
Thanks in advance
Praveen