Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Comment on this hibernate util class

 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's been a while, more into JPA these days, but have you considered the transactional nature of your solution?

WP
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Divya Janyavula
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 622
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic