@PreUpdate not invoked when updating a @ManyToMany collection

752 views
Skip to first unread message

Oded Peer

unread,
Feb 1, 2010, 4:48:27 AM2/1/10
to play-framework
Hi,

I have a base class:
@MappedSuperclass
public abstract class BaseConfigurationModel extends Model {
@Temporal(value=TemporalType.TIMESTAMP)
public Date lastChangeDate;

@PrePersist
@PreUpdate
public void updateLastChangeDate() {
lastChangeDate = new Date();
dirty = true;
}
}

and an entity:
@Entity
public class Post extends BaseConfigurationModel
{
public String name;

@ManyToMany
public Set<Comments> comments = new HashSet<Comments>();
}

I am using the CRUD module to create and update Posts.
When I update the "name" field the updateLastChangeDate() is invoked,
but when I add or remove elements from the "comments" set the
updateLastChangeDate() is not invoked.
I understand why this happens (http://stackoverflow.com/questions/
1786343/preupdate-not-firing-when-adding-to-a-collection) but I wanted
to know if you have any recommendations as to how this can be done
with Play.
Should I use Hibernate interceptors? Is there a generic JPA solution?

Thanks

Guillaume Bort

unread,
Feb 1, 2010, 10:46:02 AM2/1/10
to play-fr...@googlegroups.com
You could just override the save() method in your object:

public BaseConfigurationModel save() {
// ... udpate your object here
return super.save();
}

> --
> You received this message because you are subscribed to the Google Groups "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.
>
>

Reply all
Reply to author
Forward
0 new messages