0 Replies Latest reply on Dec 25, 2007 6:55 AM by Daniel Kane

    ManyToMany, sort by field in mapping table

    Daniel Kane Novice

      Dear colleagues,

      I have Termnal and Firmware entities , with Terminal_Firmware table that defines many-to-many relationship.
      Terminal has a collection of bound Firmwares :

      @ManyToMany(cascade = {CascadeType.PERSIST})
      joinColumns=@JoinColumn(name="tId", referencedColumnName="tId"),
      inverseJoinColumns=@JoinColumn(name="fId", referencedColumnName="Id")
      public List<Firmware> getFirmwares()
       return firmwares;

      Terminal_Firmware also contains integer column "position", which I want firmwares to be sorted by.

      Problem can be solved by adding a separate entity for Terminal_Firmware and making a query to all 3 tables, but I'd like to avoid that .

      @OrderBy annotation does not work for fields in mapping table.

      Do you know the way ?
      Many thanks in advance.