Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add support for translating instanceof #43

Open
SalehAly opened this issue Nov 21, 2016 · 2 comments
Open

Add support for translating instanceof #43

SalehAly opened this issue Nov 21, 2016 · 2 comments

Comments

@SalehAly
Copy link

SalehAly commented Nov 21, 2016

Hey

I have a super class which is extended by sub class, the super class has a Discriminator Column and each sub class has its own Discriminator value, Lets say that Animal is the super class , Cat is the sub class

now if I try this

 where(animal -> animal instanceof Cat) 

it throws an Exception

Exception in thread "main" java.lang.IllegalArgumentException: Could not analyze lambda code
org.jinq.rebased.org.objectweb.asm.tree.analysis.AnalyzerException: 
Unhandled bytecode instruction

Note that, we dont have an attribute that maps to the discriminator column, but even if we could add it and then JinQ was able pick it up and use it instead of instance of, it will still be a work around and not a perfect solution

is there any possible way to detect inheritance ?

I think since JPA 2.0, there is a TYPE command, and I think also it can detect the discriminator column.
http://stackoverflow.com/questions/7807608/how-to-create-an-instance-of-like-query-in-jpa-2-0

@my2iu
Copy link
Owner

my2iu commented Nov 21, 2016

Jinq does not support translating instanceof at the moment. Since you have a workaround (making an attribute for the discriminator column), it might be a while before I have the time to look at it.

I think JPA doesn't support casting from one type to another, so even if I were to add support for TYPE to Jinq, it would only be useful for a very small number of queries.

@SalehAly
Copy link
Author

I implemented the work around and it did the job for now,
I will just rename the issue to Add Support For transalting instanceof

Thank you

@SalehAly SalehAly changed the title Is there a possible way to check for Inheritance? Add support for translating instanceof Nov 24, 2016
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants