blaze-persistence icon indicating copy to clipboard operation
blaze-persistence copied to clipboard

Allow changing the default/implicit base node

Open beikov opened this issue 8 years ago • 3 comments

Currently we always use the query root as implicit base node or fail if there are multiple query roots. Especially for entity views it would be interesting to be able to change the default/implicit base node as that would make it easier to scope certain functionality like correlation providers. This would allow to omit the use of the correlation alias as prefix for every expression.

beikov avatar Mar 14 '17 15:03 beikov

Hello,

I'm trying to create a query with multiple root nodes :

cbf.create(em, SomethingCTE.class, "traitement")
                .with(SomethingCTE.class)
                .from(SomethingEntity.class, "t")
                .innerJoinLateralEntitySubquery("t.other", "si", "sinitial")
                .orderByAsc("date")
                .setMaxResults(1)
                .end()
                .leftJoinLateralOnEntitySubquery("t.other", "sc", "scurrent")
                .orderByDesc("date")
                .setMaxResults(1)
                .end()
                .on("date").leExpression("CURRENT_DATE")
                .end()
                .end()
                .bind(...)
                .end();

And doing so I get java.lang.IllegalArgumentException: An explicit base join node is required when multiple root nodes are used!

I guess this issue explains why, is there a way around it ?

Pilpin avatar Jul 08 '23 15:07 Pilpin

You need to specify qualified paths i.e.

cbf.create(em, SomethingCTE.class, "traitement")
                .with(SomethingCTE.class)
                .from(SomethingEntity.class, "t")
                .innerJoinLateralEntitySubquery("t.other", "si", "sinitial")
                .orderByAsc("sinitial.date")
                .setMaxResults(1)
                .end()
                .leftJoinLateralOnEntitySubquery("t.other", "sc", "scurrent")
                .orderByDesc("scurrent.date")
                .setMaxResults(1)
                .end()
                .on("t.date").leExpression("CURRENT_DATE")
                .end()
                .end()
                .bind(...)
                .end();

beikov avatar Jul 14 '23 14:07 beikov

Specifying the qualified paths does seem to work for lateral entity subqueries with a correlation path (although I can't go through because of #1756), thanks for that, but the exception is still thrown if I use entity classes

cbf.create(em, SomethingCTE.class, "traitement")
                .with(SomethingCTE.class)
                .from(SomethingEntity.class, "t")
                .innerJoinLateralEntitySubquery(SomeOtherEntity.class, "si", "sinitial")
                .orderByAsc("sinitial.date")
                .setMaxResults(1)
                .end()
                .leftJoinLateralOnEntitySubquery(SomeOtherEntity.class, "sc", "scurrent")
                .where("sc.date").leExpression("CURRENT_DATE")
                .orderByDesc("scurrent.date")
                .setMaxResults(1)
                .end()
                .end()
                .bind(...)
                .end();

Pilpin avatar Jul 14 '23 15:07 Pilpin