Add find... in GenericModel ?

12 views
Skip to first unread message

BakaOnigiri

unread,
Oct 7, 2010, 11:18:02 AM10/7/10
to play-framework
Hello,

I need to add a method find.... in the GenericModel class,

here is how I tried to to that :

@MappedSuperclass
public class DateBasedModel extends GenericModel
{
public static <T extends GenericModel> List<T> findInDay(LocalDate
day, String field)
{
Object[] bounds = OdileTools.getDayBounds(day);

return T.find(field + " >= ? AND " + field + " <= ?", new
Object[]{bounds[0], bounds[1]}).fetch();
}
}

And my model extends DateBasedModel instead of GenericModel, the
problem is a pure java problem, but I don't know how to solve it, in
fact "T.find" call the GenericModel find method, and is telling me to
anotate my model with Entity annotation.

I think the problem is that if find method is added by using
reflection.


How can I add a medthod to GenericModel ?

thanks.

Guillaume Bort

unread,
Oct 7, 2010, 12:24:58 PM10/7/10
to play-fr...@googlegroups.com
Unfortunately you can't do that is java. That's why Play uses some
bytecode enhancement. The easiest way is to use:

findInDay(Class<T> clazz, LocalDate day, String field)

Or to write a Play plugin that provides your own bytecode enhancement.
But it's way more difficult.

> --
> You received this message because you are subscribed to the Google Groups "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.
>
>

--
Guillaume Bort, http://guillaume.bort.fr

For anything work-related, use g...@zenexity.fr; for everything else,
write guillau...@gmail.com

Reply all
Reply to author
Forward
0 new messages