• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

When Command Object/POJO is not sufficient

 
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have very common issue. In my application, I am using Hibernate so I have related Java classes(POJOs) also. Now, as long as you're fetching data from one table in a query that's fine but when your query returns data from multiple tables at that time you can't map the result to any of that POJOs.
What is the solution to this scenario? One obvious solution is to make a model(again a Java class) equivalent to the result that is supposed to be return by the query. but if you have tons of queries like that then? Still is this the best solution?
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vishal Pandya wrote:I have very common issue. In my application, I am using Hibernate so I have related Java classes(POJOs) also. Now, as long as you're fetching data from one table in a query that's fine but when your query returns data from multiple tables at that time you can't map the result to any of that POJOs.
What is the solution to this scenario? One obvious solution is to make a model(again a Java class) equivalent to the result that is supposed to be return by the query. but if you have tons of queries like that then? Still is this the best solution?



If you use HQL or Criteria objects you can do that.

If you are using straight SQL, in the SQLQuery object there is a setEntity() method that also will allow it to do it to.

It all depends on if you write the queries correctly in Hibernate. I suggest reading the docs on hibernate.org on running queries.

Mark
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mark Spritzler wrote:
If you use HQL or Criteria objects you can do that.

If you are using straight SQL, in the SQLQuery object there is a setEntity() method that also will allow it to do it to.

It all depends on if you write the queries correctly in Hibernate. I suggest reading the docs on hibernate.org on running queries.

Mark


I am afraid but I don't follow you. Do you mean recordset?
 
Sheriff
Posts: 67682
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have found Criteria particularly useful when doing queries that aren't simply POJO-oriented.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vishal,

You can use Result Transformers for mapping query result from multiple tables to particular POJO.

Here you can find a tutorial

Hope it will help,

Regards,
 
Slime does not pay. Always keep your tiny ad dry.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic