I have two queries, which are both working and translatable into sql. The elements streamed in these queries are different and not connected. If I have two pre-filtered JPAJinqStreams and want to join them on one property, Jinq tells me, it is not possible, even though in SQL it is one of the easiest things to do.
Enough on these abstract stuff, let's get to an example:
I have two classes Class1
and Class2
, both of which can be tagged with class Tag
. I don't want List<Tag>
to be a delegate of all classes being able to be tagged (in this example Class1
and Class2
).
To get all valid Tag-Class1-Pairs, this query works perfectly as expected:
streams.streamAll(em, Class1.class)
.join((c, source) -> source.stream(Tag.class))
.where(p -> p.getOne().getId() == p.getTwo().getTaggedId())
.forEach(System.out::println);
Producing:
SELECT A, B FROM Class1 A, Tag B WHERE A.id = B.taggedId
Now I'd like to pre-filter both streams (e.g. permission-wise) and get them separately by calling Service-Functions:
JPAJinqStream<Class1> classStream = service.getFilteredClassStream();
JPAJinqStream<Tag> tagStream = service.getFilteredTagStream();
classStream.join(c -> tagStream)
.where(p -> p.getOne().getId() == p.getTwo().getTaggedId())
.forEach(System.out::println);
This for whatever reason results in java.lang.reflect.InvocationTargetException Caused by: java.lang.IllegalArgumentException: Could not extract code from lambda. This error sometimes occurs because your lambda references objects that aren't Serializable.
But actually there is no major difference semantic-wise. In the first example, I create the new stream from inside the stream. In the second example I use one from outside. In the first example source.stream
produces JinqStream<U>
, which is the same as getFilteredTagStream()
returning JPAJinqStream<Tag> extends JinqStream<Tag>
.
So my question is: How do I join two different streams, produced in different contexts?
enhancement