Hi,
1. The subclasses have additional attributes, but do not modify these at all.
2. The mapped superclasses are enhanced.
Is the behavior I am seeing a bug, or expected behavior? I was asking
if OpenJPA allows you to make methods on an entity which themselves
call the setters.
If this is a bug, I guess I can try to put a minimal test case
together and email it to you?
-Marc
On Dec 3, 2007 6:03 PM, <[EMAIL PROTECTED]> wrote:
> Hi,
>
> What do the subclasses look like? Do they have setIsChanged() or
> setSynchronizedAt() overridden definitions?
>
> Are the mapped superclasses enhanced?
>
> -Patrick
>
>
> On 11/30/07, Marc Siegel <[EMAIL PROTECTED]> wrote:
> > Hi Folks,
> >
> > I've noticed a certain bug that appears in some, but all of the cases
> > where I call an entity method which itself then calls an Enhanced
> > Setter on the entity.
> >
> > I've attached the code for one of my classes,
> > EntityWithSynchronizedAt, which serves as a MappedSuperClass for most
> > of my entities.
> >
> > As you can see, the method markAsSynchronized() calls setIsChanged()
> > and setSynchronizedAt(). The problem is that, in many contexts, these
> > changes to not get saved to the database, although they are present in
> > the object. I assume this is a problematic pattern for the OpenJPA
> > enhancement, as this pattern works in JBoss.
> >
> > A simple test case is to
> > - make a subclass with an additional setter
> > - create an object and call the setter
> >
> >
> > /**
> > * Base class for JPA entities which have
> > * - id (long)
> > * - createdAt (date)
> > * - updatedAt (date)
> > * - isChanged (boolean)
> > * - synchronizedAt (date)
> > */
> > @MappedSuperclass
> > public abstract class EntityWithSynchronizedAt
> > extends EntityWithUpdatedAt implements Serializable {
> > protected boolean isChanged = true;
> > protected Date synchronizedAt;
> >
> > @Basic
> > public boolean getIsChanged() { return isChanged; }
> > public void setIsChanged(boolean isChanged) { this.isChanged =
> > isChanged; }
> >
> > @Temporal(value = TemporalType.TIMESTAMP)
> > public Date getSynchronizedAt() { return synchronizedAt; }
> > public void setSynchronizedAt(Date synchronizedAt) {
> > this.synchronizedAt = synchronizedAt;
> > }
> >
> > public String toString() {
> > return
> > MessageFormat.format("{0}\t{1}\t{2,date,yyyy-MM-dd HH:mm:ss}",
> > new Object[]{
> > super.toString(),
> > getIsChanged(),
> > getSynchronizedAt()
> > });
> > }
> >
> > public void markAsChanged() {
> > setIsChanged(true);
> > }
> >
> > public void markAsSynchronized() {
> > setIsChanged(false);
> > setSynchronizedAt(new Date());
> > }
> > }
> >
>
>
> --
> Patrick Linskey
> 202 669 5907
>