0 Replies Latest reply on Nov 25, 2006 1:12 AM by Maciej Andreas Bednarz

    Create index for an @ManyToMany / @JoinTable relation

    Maciej Andreas Bednarz Newbie

      Hi there,

      I am trying to create a database index for a mapping table. My source looks like this:

       @ManyToMany(
       targetEntity=PortalUser.class,
       cascade = { CascadeType.PERSIST, CascadeType.MERGE },
       fetch = FetchType.LAZY
       )
       @JoinTable(
       name="friends",
       joinColumns={@JoinColumn(name="psid")},
       inverseJoinColumns={@JoinColumn(name="ptid")},
       uniqueConstraints={@UniqueConstraint(columnNames={"psid", "ptid"})}
       )
      


      If I try to use the following code i get an error:

       @ManyToMany(
       targetEntity=PortalUser.class,
       cascade = { CascadeType.PERSIST, CascadeType.MERGE },
       fetch = FetchType.LAZY
       )
       @JoinTable(
       name="friends",
       joinColumns={@JoinColumn(name="psid")},
       inverseJoinColumns={@JoinColumn(name="ptid")},
       uniqueConstraints={@UniqueConstraint(columnNames={"psid", "ptid"})}
       )
       @Index(name = "friendindex", columnNames={"psid", "ptid"})
      


      Does any one has a solution for this?

      Thank you very much,

      Maciej