-->
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.  [ 1 post ] 
Author Message
 Post subject: problems with sessions
PostPosted: Mon Nov 03, 2008 8:09 am 
Newbie

Joined: Wed Oct 08, 2008 6:41 am
Posts: 3
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


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

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.