According to the QueryDSL docs, (http://www.querydsl.com/static/querydsl/4.0.8/reference/html_single/#d0e2250) only the first two levels of paths are initialized in generated Q classes, so if an object A has a relationship inside a @Entity B defined by an @JoinColumn, you can't do things like b.a.id in a query to access the id for A from inside B. They have a @QueryInit annotation to use in those situations where we need to have deeper paths but the docs are very brief and I don't understand how its used. Right now Im getting an "invalid path" exception when I try to run the query inside my application. Has anyone use @QueryInit to fix a problem similar to mine ?
The query where clause (ie. in QueryDSL) is something like a.id.eq(b.a.id) where a is "embedded" inside b
The exception Im seeing is:
"org.hibernate.hql.internal.ast.QuerySyntaxException: Invalid path: 'b.a.id' [select a from A a where a.id is not null and (a.id = b.a.id and a.amount <= sum(b.amount))]; nested exception is java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: Invalid path: 'b.a.id' [select a from A a where a.id is not null and (a.id = b.a.id and a.amountCents <= sum(b.amountCents))]",
The query Im trying to "translate" into QueryDSL looks like this:
SELECT * FROM A a
WHERE a.amount <= (SELECT SUM(b.amount) FROM B b WHERE b.a_id=a.id);
The predicate ended up simply being: