I'm finding that with a number of hibernate mappings I have a simple version of an entity defined for basic CRUD operations, and then I really need an expanded version of the same entity that includes all of its associations for reporting process optimization.
For example: I have an entity (e.g. course) that has a number of related sub entities (e.g. attendees, class times etc) but I don't want to include these sub entities as properties in the main entity class structure.
To get around this I'm using the following class hierarchy...
Code:
AbstractCourse
|---- Course
|---- CoursePlusBookings
public abstract class AbstractCourse {
private int CourseID;
private String Title;
private String Teacher
}
public class Course extends AbstractCourse {
}
public class Attendee {
private int AttendeeID;
private int CourseID;
private String StudentName;
}
public CoursePlusBookings extends AbstractCourse {
private Set<Attendee> Attendees;
}
Now for all entity level CRUD operations I'm using 'Course' and 'Attendee' separately to add entries to the underlying database. However, for reporting purposes I want to use 'CoursePlusBookings, which allows me to show a list of courses with the number of bookings.
Now the only way I can find to support this approach is to have two separate mappings - one for 'Course' and a second for 'CoursePlusBookings' - both of which map to the same table. I can't find a way of implementing mapping inheritance to avoid this duplication. I did raise this question sometime ago (see
viewtopic.php?f=1&t=984333) but unfortunately the respondents misunderstood my question, so I'm asking it again.
I suppose in a way this posting boils down to a question about whether it is possible to have mapping element associations that are read only in nature. In otherwords if persisted CoursePlusBookings then the Attendee set would not be persisted as part of that operation.
Or is there another way to achieve what I'm after?