tags:

views:

63

answers:

1

I have an Interceptor for a Hibernate managed object. The File and Customer tables have an intermediate table (FileCustomer) which represents a many to many relationship between the two. This is managed in Hibernate by the File class.

@OneToMany(mappedBy = "file", cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
@Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
private List<FileCustomer> fileCustomers= new ArrayList<FileCustomer>();

We change the File object, including replacing some of the FileCustomer objects(but not changing the underlying Customer objects).

When the onFlushDirty is called, the File update contains the changed propertiess for the File object, everything is OK. However, the property collection containing the list of FileCustomer objects has the same previous and current values.

Am I missing something? How would I be able to access the previous and new values for the collection property?

+1  A: 

Check this post it will give you the idea to get both objects, basically you can store the FileCustomer in preFlush method, so you compare the collection in onFlushDirty against it.

pedromarce