Hi, I'm working on a Timesheet entry system where I have a header record with a "weekStarting" Date and child records with time for an individual date. I want to be able to retrieve the child records as part of a OneToMany relationship where the date of the child records is within the week defined by the weekStarting date on the header. The detail records may be inserted directly into the detail table from other systems, so I don't want a simple foreign key. There's also an emplid that's part of the relationship:
Header (TimesheetRequest):
Emplid: 0001234, Week Starting: 05/10/2010
Details (TimeDetail):
Emplid: 0001234, Date: 05/10/2010, Amount: 8hrs etc.
Emplid: 0001234, Date: 05/11/2010, Amount: 8hrs etc.
...
I currently have a OneToMany relationship defined like this:
Code:
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY)
@Filter(name="week", condition="time_date between :weekStarting and :weekEnding")
@JoinColumn(name="EMPLID", referencedColumnName="EMPLID")
private List<TimeDetail> details = new ArrayList<TimeDetail>();
With this I'm able to retrieve the header, set the filter using the week starting from the header, and then retrieve the correct details like this:
Code:
TimesheetRequest retrieved = (TimesheetRequest)session.get(TimesheetRequest.class, key);
session.enableFilter("week").setParameter("weekStarting", retrieved.getWeekStarting()).setParameter("weekEnding", DateUtils.addDays(retrieved.getWeekStarting(), 6));
retrieved.getDetails();
And it seems to work OK, but I wanted to know whether there was another way to define the relationship that didn't require the filter to be enabled for the session. I see that there are annotations like @When and @JoinFormula, but I wasn't sure whether I could reference a value in the header record as part of those.
Thanks, Andrew