1 Reply Latest reply on Jun 7, 2006 5:02 PM by mazz

    Extra fields on Many To Many mapping tables

    jjklappenbach

      Our company is developing an EJB solution for a schema that features auditing fields on every table, including the many-to-many mapping tables. The audit fields are constrained to non-null values, and must include dates as well as the committing user.

      The problem that I've encountered is that these fields are not handled with the @ManyToMany annotation model, at least with the current argument set we're using for the annotation. Is there additional annotation or perhaps configuration descriptors that can be used to have EJB3 / Hibernate automatically handle those fields? I've seen examples of Interceptors being used, but discussion of that strategy often leads to business owners looking like they've just stepped on a grave.

      Having additional, non-null fields on mapping tables can't be a particularly rare case. How can this best be handled through EJB3?

      One other solution I've found is limiting cascades to REFRESH and DELETE for the @ManyToMany, and creating explicit service layer API methods for association. That means creating an @Entity for each mapping table -- basically extra work.

      Thanks for your time in advance,

      Julian Klappenbach
      Lead Software Developer
      Ramp Technology Group

        • 1. Re: Extra fields on Many To Many mapping tables
          mazz

          There are threads on this in here already on this. ManyToMany doesn't handle those extra columns. I've come to terms with this by simply ignoring ManyToMany and always implementing my M-2-M relationships using OneToMany/ManyToOne - even if I don't currently use other columns in my association tables - because invariably, I always wind up needing to add columns in the end anyway. And I don't want to waste the time converting the ManyToMany to the OneToMany/ManyToOne. Just do it in the beginning and that leaves you free to add columns in the future.