3 Replies Latest reply on Oct 21, 2008 1:30 PM by adamw

    OneToMany association with Set

    abhijeetkasale

      I am facing a problem with a one to many association mapped by a

      Set
      . I downloaded the envers-1.1.0.beta2-hibernate-3.3.jar and used the
      @VersionsJoinTable
      to include that association. Following is the code snippet:

      public class Target implements Serializable {
      
      private static final long serialVersionUID = 1620943942094334329L;
      
       @Id
       @GeneratedValue(strategy = GenerationType.AUTO)
       private Long id;
      
       @OneToMany(fetch = FetchType.EAGER, mappedBy = "pk.target", cascade = { CascadeType.ALL })
       @VersionsJoinTable
       private Set<ProductwiseTarget> productwiseTargets;
      
      ...... //// other getter and setters
      }


      I have also versioned the
      ProductwiseTarget
      class and it works fine. Somehow, when I version the
      Target
      class, I get
      org.hibernate.HibernateException: could not init listeners
      exception. The stack trace also says,

      Unable to read the mapped by attribute for productwiseTargets in com.crisil.ratings.bd.masters.model.Target!
      . I am not able to figure out the reason.

      Thanks.

        • 1. Re: OneToMany association with Set
          adamw

          Hello,

          and how can your mappedBy contain a dot in it? It should be a name of a property (for example "target"). I think this may be the cause.

          Also, then using @OneToMany, you don't have to use @VersionsJoinTable. It will work without it.

          @VersionsJoinTable is just needed for the special case when you use @OneToMany and @JointTable.

          --
          Adam

          • 2. Re: OneToMany association with Set
            abhijeetkasale

            Hi Adam,

            ProductwiseTarget is a association class between product and target objects (many to many). It contains an embeddable object ProductwiseTargetPK, that's why the mapped by in Target contains a dot.

            Moreover, the target class is a superclass in my case, using Joined inheritance. Is it supported by enverse?

            What should I do in this case?

            • 3. Re: OneToMany association with Set
              adamw

              Ah ... so you have a relation inside a component?
              Unfortunately that's not supported yet (it's not part of standard JPA mappings). Also, joined inheritance isn't yet supported, only the single-table inheritance.

              --
              Adam