• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

can we use hibernate when we need to create insert statement dynamically?....

 
Ranch Hand
Posts: 551
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Thank you for reading my post
We have an application created using JDBC, for now application works but for next version we are planning to use a ORM framework as some parts of application is going to be re-writted .
now my question is :
in currect JDBC layer we have tens of dynamically created SQL statement (select / delete / update /insert) we build those statement based on user input and some other business logic.

my question is : Does hibernate support such thig ?
for example some times we select a query by joinin 3 tables when user need less details information and sometimes we should engage 5 tables.
can we do such tings with hibernate, or hibernate just allows us to have per table objects.

Thanks
 
Ranch Hand
Posts: 502
jQuery Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hibernate do supports dynamic queries. You can Insert,delete,select and delete dynamically using Hibernate.

Hibernate uses JDBC as its core. So whatever possible in JDBC is also possible with Hibernate.

Good reference to Hibernate is:

http://www.hibernate.org/152.html

HTH,
 
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
I understand where you are coming from.

You can always create an SQL Query object, and create your query string.

However, I think as you learn more about Hibernate, your current solutions will probalby change. When you talk about 3 or 5 tables being joined, the first thing that will be a "shock" to you is in regards to eager and lazy loading. You can only eager load one "many" table in such a join, as if you tried to have eager fetching with all 3-5 tables you would create a cartesian product, since Hibernate uses Left Outer Joins. So for those queries you will have to use SQLQuery and work with Object arrays, or "Select new MyObject(a, b, c)" to not have to work with object arrays, but with dynamically created queries you won't know how to create MyObject and its constructors since your query would be different each time.

Mark
 
Are you okay? You look a little big. Maybe this tiny ad will help:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic