0

Below is the HQL query which gives me the syntax error when I use join Operation with ON clause on the Collection property.

I have a Source.java file with one Collection property of the Customer bean with OneToMany mapping which is mapped by source property in Customer bean.

HQL Query :

select s.name from Source s 
join Customer c on s.customer.id = c.id

Java class snippet:

    @OneToMany(mappedBy = "source")
    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
    private Set<Customer> customer = new HashSet<>();
    
   I have Customer.java which has ManyToOne relation with Source bean  
    
    @ManyToOne
    @JoinColumn(name="source_id")
    private Source source;
    
Joe Taras
  • 15,166
  • 7
  • 42
  • 55
imtejask
  • 3
  • 3
  • 1
    I don't see any HQL query – Maurice Perry Oct 13 '20 at 12:29
  • 1
    HQL Query : select s.name from Source s join Customer c on s.customer.id = c.id – imtejask Oct 13 '20 at 12:49
  • Try something like: `select s.name from Source s join s.customer c` – Maurice Perry Oct 13 '20 at 12:55
  • It is working but I want to use ON clause – imtejask Oct 13 '20 at 13:08
  • 1
    Alright, how about: `select s.name from Source s join Customer c on c.source=s` (s.customer is not a customer: it's a set) – Maurice Perry Oct 13 '20 at 13:59
  • I tried select s.name from Source s join Customer c on s.customer.id = c Gave me org.hibernate.hql.internal.ast.QuerySyntaxException: left and right hand sides of a binary logic operator were incompatibile – imtejask Oct 13 '20 at 19:34
  • customer property in your Source class is a collection, so you can't use a JOIN with ON because you must take the indexed element to put in relation. But which is your aim? Because you can write your query in several ways – Joe Taras Oct 15 '20 at 08:06

0 Answers0