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