Hi Joel!
You might look at @PreUpdate.
@PrePersist only gets called before a em.persist() performs the sql INSERT statement. @PreUpdate
will get called before any sql UPDATE to the entity.
LieGrue,
strub
--- On Wed, 2/9/11, Joel Halbert <joel@su3analytics.com> wrote:
> From: Joel Halbert <joel@su3analytics.com>
> Subject: Does PrePersist work when merging entities? (2.0.1)
> To: "users@openjpa.apache.org" <users@openjpa.apache.org>
> Date: Wednesday, February 9, 2011, 3:06 PM
> Hi Folks,
>
> Are there any known issues around using @PrePersist
> on merge with
> 2.0,.1?
> My Entities use Property access.
>
> @PostLoad method is always called when loading entities.
> @PrePersist is called on persist, but never on merge.
>
> I'm tried using both runtime (agent) and compile time
> enhancement.
>
> Here's a sample Entity that I used for testing this.
>
>
>
> import javax.persistence.*;
>
> @Entity
> @Access(AccessType.PROPERTY)
> @Table(name="TEST")
> public class Test {
>
> private int id;
> private String name;
>
> @Id
> @GeneratedValue(strategy =
> GenerationType.IDENTITY)
> @Column(name="ID")
> public int getId() {
> return id;
> }
> public void setId(int id) {
> this.id = id;
> }
>
> @Column(name="NAME")
> public String getName() {
> return name;
> }
> public void setName(String name) {
> this.name = name;
> }
>
> @PrePersist
> void populateDBFields(){
>
> System.out.println("Hello, I happen prePersist!");
> }
>
> @PostLoad
> void populateTransientFields(){
>
> System.out.println("Hello, I happen postLoad!");
> }
>
> public static void main(String[] args)
> throws Exception {
> EntityManagerFactory
> factory = Persistence.createEntityManagerFactory(
>
> "su3", null);
> EntityManager em =
> factory.createEntityManager();
>
> // Test t = new
> Test();
> //
> t.setName("name");
> // em.persist(t);
>
> Test t =
> em.find(Test.class, 1);
> t.setName("new
> name");
> em.merge(t);
>
>
> em.getTransaction().commit();
> em.close();
>
> }
> }
>
>
>
>
> Any clues?
>
> Joel
>
____________________________________________________________________________________
8:00? 8:25? 8:40? Find a flick in no time
with the Yahoo! Search movie showtime shortcut.
http://tools.search.yahoo.com/shortcuts/#news
|