-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: @PrePersist, @PreUpdate are not called (Annotation,Session)
PostPosted: Sat Jun 14, 2008 5:52 am 
Beginner
Beginner

Joined: Wed Nov 05, 2003 7:51 am
Posts: 22
I checked the forums and the docs but cannot find an answer to this problem. It should work but it doesn't.

Hibernate version: 3.2.6 ga
Mapping documents: Annotation

I am using sessions (not entitymanager) with annotated classes.

I have an abstract root class (PersistentObject) which contains callback methods annotated with PrePersist and PreUpdate but they never seem to be called when an entity of a subclass is persisted or updated.

Are these annotations useless if one doesn't use entitymanager? This would be very strange because @Version works.

The root class for all entities:
-------------------
package limes.core;

/**
* The class containing the common properties of the persistent classes in
* the system.
*/
@MappedSuperclass
public abstract class PersistentObject {
private Long id;
private int version;
private Date created;
private Date lastModified;

public PersistentObject() { super(); }

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() { return id; }
public void setId(Long id) { this.id = id; }

@Temporal(TemporalType.TIME)
public Date getCreated() { return created; }
public void setCreated(Date created) { this.created = created; }

@Temporal(TemporalType.TIME)
public Date getLastModified() { return lastModified; }
public void setLastModified(Date lastModified) { this.lastModified = lastModified; }

@Version
public int getVersion() { return version; }
public void setVersion(int version) { this.version = version; }

@PrePersist
public void prePersist() {
setCreated(new Date());
}
@PreUpdate
public void preUpdate() {
setLastModified(new Date());
}
}
----------------------------------------------------------------

Any help is appreciated!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 14, 2008 9:28 am 
Regular
Regular

Joined: Sun Apr 13, 2008 3:04 am
Posts: 71
Location: Bangalore
Yes, this was my observation too.. Not sure if Hibernate has been JPA certified.. I see these @Prexx would play imp. lifecycle in JPA specification.

Regards,
Nagendra

_________________
Raja Nagendra Kumar,
C.T.O
http://www.tejasoft.com
TejaSoft - Specialists in Code Audit, Unit Testing and Merciless Re-factoring - Engineering Crisis Turnaround Experts


Top
 Profile  
 
 Post subject: Temporary solution
PostPosted: Mon Jun 16, 2008 4:07 am 
Beginner
Beginner

Joined: Wed Nov 05, 2003 7:51 am
Posts: 22
As a temporary solution I did it the traditional way and registered an Interceptor on the Configuration.

However, I am still interested in how to use @PreXXX callbacks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 25, 2008 2:49 pm 
Newbie

Joined: Wed Jun 25, 2008 2:48 pm
Posts: 1
Guys,

Please reply as I also have the same issue and its not working with session.

Thanks,
Rahul


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 26, 2008 3:20 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
Not sure if Hibernate has been JPA certified

this is a bit silly as JPA standard has been created basing on Hibernate.

Anyway this looks like a JPA feature, so I think you should use Hibernate's EntityManager,
the Session is not required to be JPA compliant, so use Entitymanager if you need JPA.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 27, 2008 12:53 pm 
Newbie

Joined: Fri Jun 27, 2008 12:44 pm
Posts: 4
I have the same issue too,waiting for your reply.
Thank you first.

_________________
MSN/Email: electronics-mac-sony@hotmail.com
http://www.electronics-mac-sony.com/


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 19, 2008 6:08 am 
Newbie

Joined: Mon Mar 31, 2008 2:53 pm
Posts: 4
Bump... anybody heard anything about this behaviour? I'm also experiencing it.

For the record:
Hibernate: 3.2.6
Annotations: 3.3.1
Validator: 3.0.0

Regards,
Robert


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.