aspose file tools*
The moose likes Object Relational Mapping and the fly likes Comment on this hibernate util class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Comment on this hibernate util class" Watch "Comment on this hibernate util class" New topic
Author

Comment on this hibernate util class

Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
I have around 20 Dao classes, each containing 4-6methods. So, i went for a separate Utility class. Here is the code :



Dao class



Give your valuable suggestions and improvements needed in this code


kunal
William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 859

It's been a while, more into JPA these days, but have you considered the transactional nature of your solution?

WP
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1676
    
    7

There are some issues with it.

1. The biggest issue is your private static final Session. Sessions are not thread safe. SessionFactories are.
2. config.buildSessionFactory() is deprecated as is probably evidenced by the strike through you most likely see in your IDE.
3. What is it are you hoping to accomplish with your exception handling? You might want to throw an exception in your create session and see the message you are actually throwing out on that exception.

Try something more along these lines



[How To Ask Questions][Read before you PM me]
Divya Janyavula
Greenhorn

Joined: May 24, 2011
Posts: 19
Consider if you want to use one hibernate session through one user request(using same session across multiple DAOs). As far as I know it is not a wise decision to open and close session for every DB transaction.

Is it a web application? Then you might want to use same hibernate session in a single user session. If so where do you want to place your session?
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
Thanks William P O'Sullivan, Bill Gorder and Divya Janyavula for your replies.
Its a Windows application, created using swing and hibernate.

Can anyone explain the internal proceedings if i go for getCurrentSession? In my application, i haven't used cache. The whole application basically works on CRUD.
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1676
    
    7

Discussed here:
http://www.coderanch.com/t/218463/ORM/databases/Hibernate-sessions-transactions
 
jQuery in Action, 2nd edition
 
subject: Comment on this hibernate util class