Hibernate for multiuser application

Hi,

i'm developing an application with Hibernate and Java Servlets. This application connect to MySql database. Actually, i create a SessionFactory reading connection's parameters to hibernate.cfg.xml file. In this file, there are also username and password for one user. It works, wery well. But now, i would to transform this application with multiple acces by several user. Mi idea , is create a Sessionfactory with Servlet 's init() method. After this, i would create Session'object for every user connected to application. Username and password for the user, are inserting in a html form. How can divide SessionFactory creation with user's identification ? Thanks a lot.

Message was edited by:

_nemesis_

Message was edited by:

_nemesis_

Message was edited by:

_nemesis_

[832 byte] By [_nemesis_a] at [2007-11-27 2:57:40]
# 1

I'd recommend using Spring and taking advantage of its OpenSessionInViewFilter. This associates the session with the request instead of trying to associate it with a particular user.

If you're doing concurrent access to a MySQL database you should also ensure that you're using InnoDB type tables and making use of transactions.

dcmintera at 2007-7-12 3:36:25 > top of Java-index,Java Essentials,Java Programming...
# 2

I think you are making a basic web-application mistake.

Web applications have a pool of connections, and all the connections

in a pool must have the same user name and password. (Maybe that is

not true for all databases, but that's how I've always seen it.) So the user

name here will be "webappuser" or some such generic name.

Now you want your application users to log in. Go ahead and code that,

but those use names and passwords will not necessarily be actual database

user names and passwords. There are often stored in an ordinary table

(with the password digested, of course) as application data.

Does that make sense?

DrLaszloJamfa at 2007-7-12 3:36:25 > top of Java-index,Java Essentials,Java Programming...
# 3
D'oh! Dr LJ read your post more carefully than I did.
dcmintera at 2007-7-12 3:36:25 > top of Java-index,Java Essentials,Java Programming...