wood burning stoves 2.0*
The moose likes Struts and the fly likes How to programatically configure hibernate from struts 2? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to programatically configure hibernate from struts 2?" Watch "How to programatically configure hibernate from struts 2?" New topic
Author

How to programatically configure hibernate from struts 2?

D. David
Greenhorn

Joined: Nov 06, 2008
Posts: 2
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Nov 06, 2008
Posts: 2
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

Joined: Sep 29, 2008
Posts: 12617

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.
 
 
subject: How to programatically configure hibernate from struts 2?