[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - jboss apps need to save the session in 2 different databases
gan.gary
do-not-reply at jboss.com
Sat Jun 14 23:35:09 EDT 2008
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();
I have found other post quite similar http://www.jboss.com/index.html?module=bb&op=viewtopic&t=137065 with me?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4158180#4158180
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4158180
More information about the jboss-user
mailing list