0

I need to handle prePersist and preUpdate methods for a table created automatically by JPA in a @ManyToMany ralation in a @joinTable. This table does not have an entity and I thought it would use the prePersist trigger of its counterpart table but I was not the case. The only think I can imagine is to split the @ManyToMany in two @ManytoOne and creating an @Entity to map this join-table table. Unfortunally this process is painful and I would let this be a last resort.

I am using Eclipselink as a JPA provider.

Marcelo Ribeiro
  • 113
  • 1
  • 11
  • Please, ensure that you have a complete and verifiable example to help people to understand your objective: http://stackoverflow.com/help/mcve – diogo Dec 28 '16 at 16:02
  • 1
    The mapping itself does not have events - the JPA provider is there to pick up changes, and gives you the callbacks on the entity itself through prePersist or PreUpdate events. What exactly are you trying to do that you would need an event on the mapping itself- could you just not use the existing callbacks in the owning entity? – Chris Dec 28 '16 at 16:20
  • And even if you do find a way of using the existing callbacks in the owning entity, make sure **not** to modify relationships or the persistent state of the related entities - see http://stackoverflow.com/questions/7753702/jpa-hibernate-preupdate-doesnt-update-parent-object – crizzis Dec 28 '16 at 18:07
  • I want to add some extra information to some entities in case of an update or inserts. In the case of an existing entity I set two more values to the entity (to use in an audit like procedure). It works like a charm. The problem is the client wants to get the extra information also in the mapping table (and we do not have Entity for this). In other words, the client wants to 'audit' this table as well because the data stored in this table is very important. – Marcelo Ribeiro Dec 28 '16 at 18:10
  • If that's the case, there's no going around splitting the `@ManyToMany` into two `@OneToMany` relationships. – crizzis Dec 28 '16 at 22:00

0 Answers0