-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: session question
PostPosted: Thu Aug 07, 2008 6:19 pm 
Newbie

Joined: Wed Mar 09, 2005 10:15 pm
Posts: 10
hi all,

i'm fairly new to hibernate and have a question on sessions. i'm using hibernate to point to multiple db instances. all instances have the same schema definition for the persisted object. so, i've defined my create method like this:

Code:
public Employee create(Employee employee, SchemaInfo schemaInfo) {
      Transaction tx = null;
      org.hibernate.Session session = this.getSessionFactory().openSession(getConnection(schemaInfo));
      
      try {
         tx = session.beginTransaction();
         session.persist(employee);
         tx.commit();
         session.flush();
      }
      catch (Exception e)
      {
         e.printStackTrace();
         if (tx != null)
            tx.rollback();
      }
      finally
      {
         if (null != session && session.isOpen())
            session.close();
      }
      
      return account;
   }


Code:
private java.sql.Connection getConnection(SchemaInfo schemaInfo)
   {
      Connection conn = null;
      String url = "....";
      String driver = "....";
      
      try {
         Class.forName(driver);
         conn = DriverManager.getConnection(url,schemaInfo.getUserName(), schemaInfo.getPassword());
         conn.setAutoCommit(false);
      }
      catch (Exception e) {
         e.printStackTrace();
      }
      
      return conn;
   }


The schema info is information related to the db that will persist the information. i'm wondering if this is correct ? i have a test case that is persisting the information to 2 different db's right now, but wasn't sure if i'm off base or there is a better way.

hibernate version 3.0.5
db -> oracle

thx in adv


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 08, 2008 12:32 am 
Regular
Regular

Joined: Wed Apr 25, 2007 11:44 pm
Posts: 59
i don't know that why are you not using any pooling mechanism ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.