0 Replies Latest reply on Aug 4, 2006 6:56 AM by aidan_b5

    Querying a join table

    aidan_b5

      Hi, I need to query the join table of a many to many relationship and am having trouble.

      PersistentValue class:

      @ManyToMany(cascade = {CascadeType.ALL}, fetch = FetchType.LAZY)
       @JoinTable(name = "user_filter",
       joinColumns={@JoinColumn(name="persistentvalue_id")},
       inverseJoinColumns={@JoinColumn(name="persistentuser_id")})
       public Collection<PersistentUser> getUsersAllowed() {
       if(usersAllowed == null) usersAllowed = new ArrayList<PersistentUser>();
       return usersAllowed;
       }



      PersistentUser class:

      @ManyToMany(mappedBy = "usersAllowed")
       public Collection<PersistentValue> getUserFilters() {
       if(userFilters == null) userFilters = new ArrayList<PersistentValue>();
       return userFilters;
       }



      If I try to query user_filters directly, I get a 'no such mapping exception'. Do I need to create an entity representing the join table, and if so, how do i do this?

      Your help appreciated, thanks.