Search code examples
javasqljpaeclipselinkjpql

JPA query from java Object


How can i use jpa for query over an object (not an entity)?

For example this simple code:

String [] theList = {a,b,c,d}. 
Query q = new Query("Select tl from theList tl")

Reason behind: the queries are dynamically created and executed, but the objects in the from clause of the jpql query aren't necessarily mapped tables. In some cases there are just an Object, So the actual behavior needed is modify the query during execution of the program to meet the criteria, but i don't know how to modify the query.

Edit: I Don't use native queries because of portability of code. It will be the last option.


Solution

  • I have solved using joSQL. Is a powerfull opensource tool that allows you to query over java objects using "sql". It is not jpa but satisfied my needs. Another tool i have seen that do that is called querydsl.