0

I am using JPA with hibernate in my project.

I came to a query where I need to join 6 tables. This will give 20 columns as a result.

My Entity classes are:

  • InvoiceAccount
  • AssetAgreement
  • Asset
  • LineItem
  • ProductAgreement

  • Product

My pojo class is AggregateDetail which contain all the 20 variables that I will get from the native query.

Is there any way to implement this.

Debugger
  • 494
  • 5
  • 18
izaz
  • 11
  • 2
  • 7
  • You may use CreateSQLQuery along with Result transformer to achieve this. https://stackoverflow.com/questions/55545239/get-value-from-java-lang-object-on-hibernate/55545543#55545543 – javapedia.net Apr 10 '19 at 10:30
  • In that example InvoiceItems seems to be an Entity class. But I need to assingn the result to a non entity class – izaz Apr 10 '19 at 18:24

1 Answers1

0

I think you can do this:

List<? extends Object> results=entityManager.createQuery("YOUR QUERY").getResultList();

Finally you can cast the result, of course after testing each object.

Ismail
  • 2,322
  • 1
  • 12
  • 26
  • what does "?" means here – izaz Apr 11 '19 at 04:52
  • This means any class extends from Object, as you know all the classes in JAVA extends Object class, so this mean any class you want. – Ismail Apr 11 '19 at 08:13
  • Also you must know there a is difference between List extends Object> and List the second one mean that this list accept just classes just of type Object. – Ismail Apr 11 '19 at 08:15