Home > Enterprise >  Using member of to filter in many to many relationship
Using member of to filter in many to many relationship

Time:06-04

I have this problem, to begin I have this example class

@Entity
public class A  {
    private String name;
  @id
  private Integer id;
  
    @ManyToMany(cascade = {CascadeType.PERSIST,CascadeType.MERGE}, fetch = FetchType.LAZY)
    @JoinTable(name = "formof_undertaking_subproduct", 
    joinColumns = @JoinColumn(name = "a_id"), 
    inverseJoinColumns = @JoinColumn(name = "b_id"))
    private Set<b> bSet;

and I want to do this query

@Query("select distinct entity from A entity where :bId member of entity.b.id")
List<A> getAbyB(@Param("Bid")Integer Bid);

but when I execute this query I get this eception:

Parameter value element [1] did not match expected type

Because for some reason, it expected a B object, but I want to use a B.id the integer id.

Any idea to solve it? thanks for your time and sorry for my english, it's not my native language.

CodePudding user response:

Finally, I have done a new query using a simple join, the query would be:

select distinct entity from A entity join entity.b other where other.id = :id;
  • Related