-->
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.  [ 1 post ] 
Author Message
 Post subject: Alternatives to filtering a OneToMany collection
PostPosted: Thu May 13, 2010 3:10 pm 
Newbie

Joined: Thu May 13, 2010 2:41 pm
Posts: 1
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.