Win a copy of Head First Android this week in the Android 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • Al Hobbs
  • salvin francis

Hibernate and Struts 2 question

Posts: 7
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to learn how to work with Struts 2 (along with JPA and Hibernate) and I've written this piece of code to start my learning project:

This is Registeration.jsp:

This is struts.xml

This is the action class (

And this is

UserService and and UserServiceImpl are the same just without the implementation.

Now for my questions:
I am aware that my UserDAOImpl is written pretty bad but I just wanted to see if it works. I want some advice about how should I be writing this DAO classes, I suppose I shouldn't be creating an instance of EntityManager and EntityManagerFactory in every class and begin and close a transaction for each persist(). I assume that if I want this done write, I should write another layer, probably an abstract class or an interface which will contain the functions that are common to all DAO classes and the all the EntityManager operations should be done from there, and where should I close the EntityManager and the EntityManagerFactory, I know it should be done at the end of the application, but how do I tell it in a JEE application. I don't have any actual experience with this so I was hoping to get some advice from experienced users on how these things are done in the real world.

I actually had a question more related to the code I've pasted here but I managed to resolve it during the writing of this post, so I'm left with only one (and quite big) question.

I know this question is a little abstract and there is more than one correct answer for it, but I would like to get some direction on this.

Thanks in advance!
Posts: 9626
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I haven't used JPA, but there is a Hibernate Session Plugin for Struts 2.
I didn't know about it when I wrote my last Hibernate Struts app, so I just wrote an interceptor to take care of the Hibernate setup and put a Session in the action.
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic