am using Hibernate-core-jakarata:5.6.15.FInal now . And also we have hibernate.cfg.xml and hbm.xml files .
Session creation as below …--------------
public static Session currentSession(String instance) throws
HibernateException {
log.finest("currentSession called for " + instance +
" [" + Thread.currentThread().getName() + "]");
// Check if the thread local object is registered with the instance
ThreadLocal tl = null;
synchronized (sessionFactoryLock) {
tl = (ThreadLocal) sessionPerThreadMap.get(instance);
if (tl == null) {
log.finest("Session not found for instance " + instance +
" [" + Thread.currentThread().getName() + "]");
// Check if the session factory is created. If not, initialise it
SessionFactory factory = (SessionFactory) sessionFactoryMap.get(
instance);
if (factory == null) {
log.finest("Session factory not found for instance " + instance);
HibernateUtil.initFactory(instance);
}
tl = (ThreadLocal) sessionPerThreadMap.get(instance);
}
}
Session s = (Session) tl.get();
// Open a new Session, if this Thread has none yet
if (s == null) {
log.finest("Opening new session for instance " + instance +
" [" + Thread.currentThread().getName() + "]");
s = ((SessionFactory) sessionFactoryMap.get(instance)).openSession();
((ThreadLocal) sessionPerThreadMap.get(instance)).set(s);
}
return s;
}
------session factory creation –
Configuration cfg = new Configuration();
//Read in the defaults from persistence.jar
cfg.configure(HibernateUtil.class.getResource("/hibernate.cfg.xml"));
//Read in list of persistable POJOs
cfg.configure("/hibernate_" + instance + ".cfg.xml");
if(!useDataSource(cfg)) {
// Name for connectionpool
cfg.setProperty(HibernateConnectionProvider.POOL_ID_PROPERTY_NAME,
instance);
// Resolve database name used in DB_INFO_FILE
String dbName = resolveDatabaseName(cfg, instance);
// Read connection information from DB_INFO_FILE and set
// Hibernate configration parameters
if ((dbinfo != null) && (dbinfo.getProperties(dbName) != null)) {
configureDBInfo(cfg, dbName);
}
else {
log.info("Database connection information not set in the " +
"DB_INFO_FILE for " + dbName + ". Expecting " +
"information to be found from Hibernate configuration");
}
}
log.info("Calling Hibernate configuration listeners for " + instance + " ...");
cfg = callConfigurationListeners(cfg, instance);
log.info("Building Hinernate session factory for " + instance + " ...");
// create session factory
SessionFactory sf = cfg.buildSessionFactory();
// add session factory to a map
sessionFactoryMap.put(instance, sf);
// add ThreadLocal to a session map
sessionPerThreadMap.put(instance, new ThreadLocal());
return sf;