hibernate - JPA @PreUpdate not called on all entities -


i have @mappedsuperclass contains metadata stuff creation , last modified date. entities extend class. class has method annotated @preupdate set these properties before according action.

what driving me crazy work entity , c not b. extend baseentity directly. there 0 reason should behave differently. more confusing @prepresist called correctly on of entities, b.

anyone has idea why happens? it's driving me nuts...

public class extends baseentity {}  public class b extends baseentity {}  public class c extends baseentity {}  @mappedsuperclass public abstract class baseentity implements serializable {      @getter     @setter(accesslevel.protected)     @version     private long version;      @getter     @setter(accesslevel.protected)     @temporal(temporaltype.timestamp)     @column(name = "created")     private date created;      @getter     @setter(accesslevel.protected)     @temporal(temporaltype.timestamp)     @column(name = "last_modified")     private date lastmodified;      @getter     @setter(accesslevel.protected)     @column(name = "created_by")     private string createdby;      @getter     @setter(accesslevel.protected)     @column(name = "last_modified_by")     private string lastmodifiedby;      @preupdate     public final void updatemetadata() {         lastmodified = new date();         if (securitycontextholder.getcontext().getauthentication() != null) {             lastmodifiedby = securitycontextholder.getcontext()                     .getauthentication().getname();         }     }      @prepersist     public final void createmetadata() {         created = new date();         lastmodified = created;         if (securitycontextholder.getcontext().getauthentication() != null) {             final string username = securitycontextholder.getcontext()                     .getauthentication().getname();             lastmodifiedby = username;             createdby = username;         }     } } 

sorry guys issue follows:

the tests run using springjunit4classrunner. issue test entity b annotated @transactional. means @preupdate called after test completes , hence test fails.

the behavior same entities if annotated in same way regarding @transactional.

for @prepersist seems called instantly before transaction completes , hence no issue there.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -