Here you are ..
import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.PostLoad;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
@Entity
public class LeaveItem implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue (strategy = GenerationType.IDENTITY)
private Long id;
private Date dateStart;
transient private int start;
transient private int end;
transient private int month;
transient private int year;
@SuppressWarnings("unused")
private int monthTag; // de-normalize
@SuppressWarnings("unused")
@PostLoad
private void postLoad() {
Calendar calendar = Calendar.getInstance();
calendar.setTime(dateStart);
start = calendar.get(Calendar.DAY_OF_MONTH);
month = calendar.get(Calendar.MONTH) + 1;
year = calendar.get(Calendar.YEAR);
}
@SuppressWarnings("unused")
@PrePersist
@PreUpdate
private void setMonthTag() {
this.monthTag = DateUtil.toIntTag(dateStart); // to YYYYQMM
}
....
}
On Thu, May 6, 2010 at 4:24 PM, Simon <[email protected]> wrote:
> Well I'm confused then. I've annotated my class with @PostLoad,
> @PrePersist and @PreUpdate.
>
> The @PrePersist and @PreUpdate methods never get called, whether the
> methods are located in the @Entity annotated class or in a defined
> @EntityListeners annotated class. I've tried leaving the persistence
> to the DN dirty-checking persistence and also by manually re-
> persisting the entity using the EntityManager's persist method.
>
> The @PostLoad method is only ever called if the entity is loaded via
> the EntityManager's find method - if you retrieve a list of the
> entities via a JPA defined query then the @PostLoad method just isn't
> called.
>
> To the couple of people who have this working, have you got some
> example code/configuration you can share?
>
> On May 6, 10:15 am, Chau Huynh <[email protected]> wrote:
> > My entity classes were annotated, and work both in local and appspot.
> Thanks
> >
> >
> >
> > On Thu, May 6, 2010 at 4:02 PM, Simon <[email protected]> wrote:
> > > Has anyone managed to get the JPA lifecycle callbacks to work?
> >
> > > I've annotated methods with @PrePersist and @PostLoad and the methods
> > > just never get called. I followed the documentation at
> >
> > >http://www.datanucleus.org/products/accessplatform_2_0/jpa/lifecycle_.
> ..
> > > just to make sure that my methods had the correct signatures.
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "Google App Engine for Java" group.
> > > To post to this group, send email to
> > > [email protected].
> > > To unsubscribe from this group, send email to
> > > [email protected]<google-appengine-java%[email protected]>
> <google-appengine-java%[email protected]<google-appengine-java%[email protected]>
> >
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/google-appengine-java?hl=en.
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> "Google App Engine for Java" group.
> > To post to this group, send email to
> [email protected].
> > To unsubscribe from this group, send email to
> [email protected]<google-appengine-java%[email protected]>
> .
> > For more options, visit this group athttp://
> groups.google.com/group/google-appengine-java?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine for Java" group.
> To post to this group, send email to
> [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-appengine-java%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-appengine-java?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine-java?hl=en.