hi there!
i have a problem with hibernate sessions.
i have a webservice: in my client side, i read from a database and i build an hibernate object. after that, i send my hibernate object to my service side, wich has other database. my problem is the hibernate session is the same.
my code is like this:
my session factory:
Code:
public static Session currentSession(String key) throws HibernateException {
HashMap<String, Session>
sessionMaps = (HashMap<String, Session>) sessionMapsThreadLocal.get();
if (sessionMaps == null) {
sessionMaps = new HashMap();
sessionMapsThreadLocal.set(sessionMaps);
}
// Open a new Session, if this Thread has none yet
Session s = (Session) sessionMaps.get(key);
if (s == null) {
s = ((SessionFactory) sessionFactoryMap.get(key)).openSession();
sessionMaps.put(key, s);
}
return s;
}
my service session (with a particulary xml file: <property name="hibernate.connection.url">jdbc:mysql://XXX:3306/
iglab</property>)
Code:
public ManejadorSincronizar() {
try{
HibernateMultiplesConfig.buildSessionFactory("servicio", "/hibernateServicio.cfg.xml");
}catch (Exception ex) {
throw new RuntimeException("Excepción construyendo SessionFactory: " + ex.getMessage(), ex);
}
}
public Session getSession()
throws HibernateException {
return HibernateMultiplesConfig.currentSession("servicio");
}
my client session (with another particulary xml file: <property name="hibernate.connection.url">jdbc:mysql://XXX:3306/
iglabws</property>)
Code:
public ManejadorSincronizar() {
try{
HibernateMultiplesConfig.buildSessionFactory("cliente", "/hibernateCliente.cfg.xml");
}catch (Exception ex) {
throw new RuntimeException("Excepción construyendo SessionFactory: " + ex.getMessage(), ex);
}
}
public Session getSession()
throws HibernateException {
return HibernateMultiplesConfig.currentSession("cliente");
}
and here is my problem:
Code:
public void insertarSolicitud(Solicitud solicitud) throws Exception {
Session session = null;
Transaction tx = null;
try {
session = getSession();
tx = session.beginTransaction();
Solicitud sol = new Solicitud();
sol.setFecha(solicitud.getFecha());
sol.setNumeroSolicitud(solicitud.getNumeroSolicitud());
sol.setIdSolicitud(2);
session.save(sol);
tx.commit();
} catch (Exception e) {
tx.rollback();
throw new Exception(e);
} finally {
if (session != null) {
HibernateMultiplesConfig.closeSession();
}
}
}
my object session and my object transaction are always my client database, they are never my service database.
can anybody help me please??
cheers
QuiQue