Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Chosing HIbernate Technology over JDBC

 
Azrael Noor
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A Project which which was made on Standard SQL Queries, having nearly 100 Queries (having different updatings insertions and selections), Using executeUpdate and executeQuery to run whole.

If the database portion of project is shifted to Hibernate technology, will Queries reduce?
How much Hibernate harm the speed of project?

I have made slight demo on it, and i found it bit slow..





Please guide

thank you
 
Bogdan Baraila
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The debate Hibernate vs JDBC it's very long but usually Hibernate wins all the time. In your example if you already have more then 100 queries, Hibernate would proven itself a better solution. But your hibernate example it's not really got (maybe you need to study hibernate better before you can make your own ideea). For example there is no reason to update on object with createQuery. Hibernate already has his own methods for saving, deleting, updating, loading etc. (session.save(object); session.saveOrUpdate(object) ...) or in function of your arhitecture you can use EntityManager (for a JPA way) or HibernateDaoSupport (if you use Spring).
Regarding speed your example it's also not very good. If you make for example 4 consecutive updates on the same object Hibernate will make this in a single transaction (thanks to his session cache) and it will be surely more fast then JDBC.
And regarding the number of queries - in one of my projects i have made a GenericHiberanteDAO in which i have generic methods for all the basic operation (save, update, delete, find, searchByCriteria with or without pagination etc) and if i need to add a new entity I just need to extend my class (and no extra code needed) for database operation. And this are just a few of the Hibernate advantages.
 
Azrael Noor
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my first work on it.

Yes i need to study Hibernate in more details, basically usage.

Yes Hibernate provide update using session object, but i found it updating all columns (which lead null entries) so i used this.

No knowledge about JPA Entity Manager and HibernateDAOSupport and never used any in hibernate till now.

Will study GenericHibernateDAO.

Could you provide me some project(link or other source) which follow well design and pattern and could guide me well
how professionally work in hibernate goes?

I thank you for your kind suggestion n help

JUST TELLING BUT ABOUT MY WORK

1) 4 Schemas - 4 Config Files
2) 20 - 25 Tables - 20 - 25 Mapping files (may extend to 30 - 40)
3) 20-25 Bean Classes

Ok thought?

and ya which version should i prefer?
 
Bogdan Baraila
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could start with the last hibernate version. Please take a look at a basic tutorial: http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/tutorial.html
Also if you don't want null values you can set up the default value for every field from mapping files or also you can use the dynamic-insert, dynamic-update features (it will create on insert/update query only with the modified columns). I know that this doesn't tell you anything but at least once you get more familiar with Hibernate you will know what to look.
 
Azrael Noor
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please suggest should i use different Sessions for each transaction, in above example i mentioned?
means if i have to use 10 inserts in single process, i need to open 10 sessions, as i need not to update all fields for particular table



 
Bogdan Baraila
Ranch Hand
Posts: 43
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No you should not open 10 session to makes 10 updates. Creating session is expensive. This is the reason for which hibernate has a SessionFactory which offers the getCurrentSession method. This method will get the current open session or it will open a new one (if there is no open session).
 
Azrael Noor
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You,

I will not open multiple sessions for it

For connecting 4 Databases

> I have made 4 Configuration files(for four database connections), as i haven't found any settings in Single Configuration file. Each database will have it's own Session object (Single Session object for transaction...If need to close session)
> I am making Mapping files, it takes time some tables have 10, 20, 30 Columns even more). I am making 1 Mapping File per table, which seems to me bad, but let me go on, if it will embed in one Mapping file only, i will do that.
> I have to create multiple bean classes(POJO) for different table and will combile bean classes where required.

just used dynamic-update="true", to update and saw underlying queries and checking out more out of it

Have to look on Connection pooling, third party connection pooling and other configuration options. Pooling underastanding is bit complex for me because never used it before.



Hope going good?
 
Bogdan Baraila
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No problem .
Actually for each database you will have a SessionFactory configured that will handle your sessions. About the mapping since you have so many tables - don't forget that you can use annotations directly in the POJO class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic