0

I need to do UNION operation on 2-3 tables using native query and need to map the result in custom object. same thing is not possible with JPA as JPA does not support UNION clause.

I heard about SqlResultSetMapping, is it useful in this case?

How and where to use this, any link or something? did not get much information on the google.

Anjali
  • 1,623
  • 5
  • 30
  • 50

1 Answers1

0

Here is a link providing information about both alternative to solve the problem and also the using resultset. UNION to JPA Query

Query query = em.createQuery("SELECT p FROM Person p  WHERE title = theTitle", Person.class);
Query query2 = em.createQuery("SELECT p FROM Person p  WHERE firstName = theFirstName", Person.class);
List<Person> list = query.getResultList();
List<Person> list2 = query2.getResultList();
LinkedHashSet<Person> result = new LinkedHashSet<Person>();
result.addAll(list);
result.addAll(list2);
Garvit Khamesra
  • 375
  • 2
  • 9
  • Can I use JPA repositories and eclipseLink both in the same application? As I have already done all of the queries using JPQL crud repositories. only one query has UNION which is not supported by JPQL, so I am looking for other options. – Anjali Dec 24 '18 at 06:06
  • So instead you can do which I added in the answer now. – Garvit Khamesra Dec 24 '18 at 06:16