Hi,
I'm not quite sure whether this is a Hibernate or a JBoss issue, so I'll just post the question here. I'm having a little trouble defining a working and conceptionally correct way of configuring the database access from within a EJB.
As background: Currently, I'm running a servlet in which a couple of Manager classes are stored, which implement my business logic. The controller servlet calls these business logics and then passes the results to a JSP for presentation.
One of these Manager instances is a DatabaseManager which at initialization reads a few property files and builds up a series of SessionFactory instances to a series of databases.
Now I want to port the complete application to J2EE, where each manager will be an EJB3 stateless bean.
My question right now is: How to I set up the hibernate configuration correctly? The goal is to do something like this:
Code:
@javax.ejb.Stateless
public class FooManager {
public int bar(String databaseName) {
SessionFactory factory = Helper.getSessionFactory(databaseName);
Session session = factory.openSession();
try {
int queryResult = AnotherHelper.countRecords(session);
return queryResult;
} finally {
session.close();
}
}
}
I experiemented a little bit using the Hibernate MBean configuration but haven't got the clue completely. The mapper classes I've stored within my application JAR archive should be mapped to different databases, so this also means SessionFactory instances, so I need to be able to manually control which mapper class should be used during the initialization of each SessionFactory.
But so far I can't find any part within the existing documentation that describes how to explicitely map classes to a SessionFactory.
Are there any tutorials available that describe this kind of setup?[/code]