Reputation: 199
I have a similar db structure. The only difference that I have more tables on the path from A to C entity:
And I have following mapping for this structure:
@Entity
@Table(name = "a")
class A {
@Id
private int id;
private String title;
@ElementCollection(targetClass=String.class)
@Formula("(select (c.useful_information) from A a " +
"join B b on a.id = b.a_id " +
"join C c on b.id = c.b_id " +
"where a.id = id)")
private List<String> usefulStuff;
}
My aim is to get a list of all useful things from table C in entity A.
But I get syntax errors.
Could you say what's wrong in my example? And maybe you know better way for this purpose?
Upvotes: 6
Views: 9018
Reputation: 1736
The problem in your @Formula
annotation is the "from A a". The value passed to this annotation is actually SQL, not JPQL.
Thus, if you want to alias the table to reference it elsewhere, you need to rather write FROM A AS a
.
Upvotes: 3