Win a copy of GANs in ActionE this week in the AI forum
or WebAssembly in Action in the JavaScript 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

How to programatically configure hibernate from struts 2?

 
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 ]
 
Author
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
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.
 
A sonic boom would certainly ruin a giant souffle. But this tiny ad would protect it:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!