• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
raminaa niilian
Ranch Hand
Posts: 551
  • Mark post as helpful
  • send pies
  • 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
 
Prabhu Venkatachalam
Ranch Hand
Posts: 502
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • 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,
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic