I have a jboss apps need to save the session in 2 different databases.
Does it mean i need to do something like this:
public MyClass() throws NamingException { InitialContext ctx = new InitialContext(); //TODO : use "hibernate.cfg.xml" if tester SessionFactory sessionFactory = (SessionFactory) ctx.lookup("java:/hibernate/SessionFactory"); //SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); session = sessionFactory.openSession(); // session 2 SessionFactory sessionFactory2 = (SessionFactory) ctx.lookup("java:/hibernate/SessionFactory2"); session2 = sessionFactory2.openSession(); } // this go to db 1 Transaction tx = null; try{ tx = session.beginTransaction(); Vector v = new Vector(hash1.keySet()); Collections.sort(v); Long nUID = null; Iterator it = v.iterator(); while (it.hasNext()) { nUID = (Long)it.next(); Obj1 obj1= hash1.get(nUID); session.save(obj1); } session.flush(); // this go to db 2 Transaction tx2 = null; try{ tx2 = session2.beginTransaction(); Vector v = new Vector(hash2.keySet()); Collections.sort(v); Long nUID = null; Iterator it = v.iterator(); while (it.hasNext()) { nUID = (Long)it.next(); Obj1 obj1= hash1.get(nUID); session2.save(obj1); } session2.flush();