java - jpa native query control entity(part 3) -
retrieve company table
getentity.javastring table = "company"; string q = "select * " +table; query query = em.createnativequery(q, company.class); list<company> list = query.getresultlist(); ...
retrieve staff table
getentity.javastring table = "staff"; string q = "select * " +table; query query = em.createnativequery(q, staff.class); list<staff> list = query.getresultlist(); ...
my questions how control ? following:
em.createnativequery(q, ?); list<?> list = q.getresultlist();
any ideas or suggestion?
another option pass class entityclass argument find method , can try , derive table name entityclass using reflection , use entityclass type argument createnativequery method.
hope helps!
Comments
Post a Comment