This week's book giveaway is in the General Computing forum.
We're giving away four copies of Emmy in the Key of Code and have Aimee Lucido on-line!
See this thread for details.
Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

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

 
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
 
Ranch Hand
Posts: 502
jQuery Spring Java
  • 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,
 
ranger
Posts: 17344
11
Mac IntelliJ IDE 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
 
Time is mother nature's way of keeping everything from happening at once. And this is a tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!