Please use the google group to ask questions - thanks.

by Eabin 08 May 16:14
Condtions for OneToMany mappings

Sorry to slightly mis-use the forums to get help :)

I am not aware of a method to add conditions to joins. Is there any way to do this that I didn't see, or would this be a nice-to-have feature?

I would like to use it e.g. to only load relations that don't have the deleted flag set to 1.

Something like this:

class Event {
...
@OneToMany
@OrderBy("cdate")
@Include("deleted=1")
private List<Comment> comments;

}

Of course the @Include(...) is just a quick suggestion, there would be most likely a better annotation to achieve the goal.

Thanks & regards,
Eabin

09 May 06:07
by Rob

>> Sorry to slightly mis-use the forums to get help :)
Not at all, this is exactly what the forums are for.

Certainly this seems like a good suggestion/enhancement to me in that it is often considered bad form to delete data, and instead set a flag.

Should be a pretty straight forward enhancement. I'll look into it.

Thanks, Rob.

05 Nov 10:14
by Rob

I have added this to v1.0.0.

The annotation will be called @Where and have a clause.

@OneToMany
@Where(clause="deleted=1")
List<Comment> comments;

And so "deleted=1" is a SQL literal that is added to the where clause for lazy loading of the comments as well as when the comments are fetched via a join ... (find topic join comments ...)

23 Feb 11:52
by Eabin

i totally missed this comment. this is awesome, so to speak. will try it out immediately :)

Create a New Topic

Title:
Body:
 
Introduction User Guide (pdf) Install/Configure Public JavaDoc Whitepapers
General Database Specific Byte Code Deployment Annotations Features
Top Bugs Top Enhancements
woResponse