implementing interface Where<U extends Object, E extends Exception> and passing impl. to where()

35 views
Skip to first unread message

Beniamin Dziurdza

unread,
Apr 18, 2019, 6:45:32 AM4/18/19
to Jinq
Is it possible? 

Please note, that one can implement Predicate<T> and pass such class to filter method of standard stream,

but, when I try to use  class that implements JinqStream.Where<MyEntity, Exception>  in where() method it throws exception in runtime:

java.lang.IllegalArgumentException: Could not extract code from lambda. This error sometimes occurs because your lambda references objects that aren't Serializable.
at com.bdsystems.domain.test.JpaTest.integration(JpaTest.java:92)

(everything is serializable, so this is not reason I assume)

Best regards,
Beniamin





Jinq

unread,
Apr 18, 2019, 11:32:14 AM4/18/19
to Jinq
The current version of Jinq no longer supports translating lambdas implemented as classes into SQL queries. I think the Scala version of Jinq somewhat supports it, but that's very old and not really maintained. You can

1. Turn off the translation of lambdas into SQL queries (I think it's the "exceptionOnTranslationFail" option)
2. Write your lambdas using Java lambdas (those can still be stored in variables or created in helper methods, so you really aren't losing much as compared to having full classes)
Message has been deleted

Beniamin Dziurdza

unread,
May 1, 2019, 4:18:51 PM5/1/19
to Jinq
Could you elaborate a little more about (2)?

Is any way to combine two lambdas to obtain a new one, for instance, I tried:

        JinqStream.Where<MyUser, Exception> id1 = u -> u.getId() == 1;
        JinqStream.Where<MyUser, Exception> id2 = u -> u.getId() == 2;
        JinqStream.Where<MyUser, Exception> id1_or_id2 = u -> id1.where(u) || id2.where(u);

(id1 and id2 works perfectly) but passing id1_or_id2 to where() throws:

java.lang.IllegalArgumentException: Could not analyze lambda code
at com.bdsystems.domain.test.JpaTest.integration(JpaTest.java:115)
Caused by: org.jinq.rebased.org.objectweb.asm.tree.analysis.AnalyzerException: Unknown method org/jinq/orm/stream/JinqStream$Where:where(Ljava/lang/Object;)Z encountered


Best regards,
Beniamin
Reply all
Reply to author
Forward
0 new messages