On Wed, Jul 22, 2009 at 8:07 AM, Kevin Sutter <[email protected]> wrote:
> Hi Adam, > > On Wed, Jul 22, 2009 at 5:37 AM, Adam Hardy <[email protected] > >wrote: > > > Kevin Sutter on 21/07/09 14:42, wrote: > > > >> > >> o In the Setter method for the proxied attribute, you must modify the > >> value > >> getting set. In this scenario, the Calendar object was being modified > in > >> the setDate method via the set() method. > >> > > > > I thought putting code in your entities' setters and getters was > considered > > bad practice. Are you saying that there is much code in OpenJPA to cater > for > > this kind of thing? > > > You are correct. Putting code in an entity's setters and getters is not a > best practice. But, it's not forbidden either. OpenJPA actually logs a > warning message when this situation is detected. But, we do not prevent > it. Nor does the JPA spec forbid it. > I think Craig put it rather well here [1]. Putting code in accessor methods is probably okay if you use field access. When you use property access it gets easier to shoot yourself in the foot. Moving to field access might be the easiest workaround for this particular problem. This is probably something that should be explained better either in the manual or on the wiki (maybe a FAQ page). [1] http://markmail.org/message/gctzqmtjvxaejyxw > > This is actually one of the reasons why I didn't go forward with a patch > just yet. Maybe the resolution will be to harden this warning message and > not allow this type of modifications in the setters if you are using > property-based access. But, to be honest, that seems a bit harsh. If > OpenJPA can just be a tad bit smarter when loading entities from a query > result set, then we could satisfy this request. Even if it's not a best > practice. > +1, we can be smarter about this - even if it is a bit tricky to get into this situation. -mike > > Kevin > > > > > > Regards > > Adam > > >
