openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From plins...@gmail.com
Subject Re: Entity methods which call Setters are not working
Date Mon, 03 Dec 2007 23:03:56 GMT
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 <marc.siegel.17@gmail.com> 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

Mime
View raw message