Hi , Is there a seam-way to implement @Entitylisteners ? I've read in the book 'Java Persistence with Hibernate' that the user of EntityManagers is not allowed in callbacks. However; thats the usecase:
I've two Entities which are associated through a @ManyToMany association and i like to implement a last-save-wins-strategy for this set. | @Entity | @Table (name="t_foo") | @EntityListeners(value={Foolistener.class}) | public class Foo { | @Id | private Long id; | | @Basic | private String name; | | @ManyToMany (fetch=FetchType.LAZY) | @JoinTable (name="t_foo_bar", | [EMAIL PROTECTED](name="foo_id"), | [EMAIL PROTECTED](name="bar_id")) | private Set<Bar> bars; | | ..... | | } | | @Entity | @Table (name="t_bar") | public class Bar { | @Id | private Long id; | @Basic | private String name; | @ManyToMany (fetch=FetchType.LAZY, mappedBy="bars") | private Set<Foo> foos; | | .... | } | | public class Foolistener { | | @PrePersist | public void prePersist (Foo foo) { | // delete the all entries in t_foo_bar which | // reference too foo.getId() | } | | @PreUpdate | public void preUpdate (Foo foo) { | // delete the all entries in t_foo_bar which | // reference too foo.getId() | } | | } | The first issue on this is, that the callback is only called if the Entity-fields are changed, but not, if the included set changed only. Does anyone know why? I know i could add a 'changed-set' - flag .. which is not very comfortable if the set is changed directly ;) I tried to add @Name and @In annotations to the FooListener - but this seams not to work. I've not much experience with Hibernate-jpa because i worked with jpox-jdo before. If i remember correctly it was no problem to have (restricted) database-access in callback-methods . Any ideas ? View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4079929#4079929 Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4079929 _______________________________________________ jboss-user mailing list jboss-user@lists.jboss.org https://lists.jboss.org/mailman/listinfo/jboss-user