Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to programatically configure hibernate from struts 2?

 
D. David
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I'm trying to learn struts 2 / hibernate so i've started working on a login page. I'm using this tutorial Struts 2 + Spring 2 + JPA.

I managed to integrate struts with spring and i've created my UserService, no problems thus far.

Now comes the tricky part, i want to make hibernate connect to the database with the username and password supplied in the login page. From what i understand from that tutorial, spring manages behind the scenes the configuration and initialisation of hibernate and then it injects a EntityManager object into my UserService.

So my question is this, is there any way to programatically configure each instance of hibernate within struts ? Or are there any alternatives i can use ?
[ November 06, 2008: Message edited by: D. David ]
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by "each instance of Hibernate"?

The Hibernate docs describe many ways to connect to a DB via Hibernate, including programmatically. What specific issues are you having?

(Technically this is a purely Hibernate question; as such, it might be better asked in a Hibernate forum

Dave
 
D. David
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the answer, well i wasn't sure where to put the topic since i'm having touble with integrating struts with hibernate so i figured it might be a struts questions.

Well the thing is that from what i've read so far when i'm trying to use hibernate with struts i have to let the struts spring plug-in initialize a EntityManager object and inject it in my UserService. And i do this by writing this in the applicationContext.xml:



As you can see i specify here the username and password with which the connection to the database should be made. What i want to do is to have a form on the first page from which i get my username and password and to use those to connect to the database.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's certainly the typical scenario--normally a web application will have a single database user (in fact I haven't seen otherwise in 10 years). It's not a requirement, though--if you're not going to go that route then following the regular Hibernate documentation should work fine.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic