• 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
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

Comment on this hibernate util class

 
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
 
Ranch Hand
Posts: 859
IBM DB2 Chrome 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
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • 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

 
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.
 
Normally trees don't drive trucks. Does this tiny ad have a license?
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!