-->
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: Problem to understand the transaction session mechanism
PostPosted: Wed Mar 04, 2009 5:46 am 
Beginner
Beginner

Joined: Wed Jan 28, 2009 10:16 am
Posts: 37
Hello,


I am here to ask you a question about transaction and session management. Because I know you are experimented.

This is my problem :
When I want to save or get information from the data base, I use a session and do some operation on it like :
Code:
List<Object> results = session.createQuery("from File").list();
or
session.saveOrUpdate(File);

But when I want to save some data in data base, I need to begin a transaction and commit after the operation on session like this :
Code:
Transaction transaction = session.beginTransaction()
session.saveOrUpdate(File);
....
transaction.commit();


The problem is that I have implemented a DAOFile class in which I just made the operation on session.

And I hava a service that use this DAOFile class method, that I need to surrond with transaction...

A person tell me that I must use Interceptor in order to be sure to initialise this mecanism or transaction just one time during all the necessary operation. But I do not understand what to do know, because I do not understand why there are a lot of different session during one transaction and why I do not close this session and why, if I close one, the other operation does not work after....

This is my current architecture and maybe where comes the problem ?:
This is my HibernateUtil initialisation of configuration and session.
Code:
public class HibernateUtil {
   private static final SessionFactory sessionFactory;
   
   static {
      try {
         Configuration annotationConfiguration = new AnnotationConfiguration()

           .addAnnotatedClass(Dossier.class)
               annotationConfiguration.setInterceptor(new BDInterceptor());
           
         
         
             sessionFactory = annotationConfiguration.configure().buildSessionFactory();                
         
         
      } catch (Throwable ex) {
         throw new ExceptionInInitializerError(ex);
      }
   }
   
   public static Session getSession() throws HibernateException {
      return sessionFactory.openSession();
   }


This is my DAO class :
Code:
public class DAODossierImpl {
...
      public List<Object> getAll() {
      Session session = HibernateUtil.getSession();
      List<Object> results = session.createQuery("from Dossier").list();
      return results;
   }


This is my Service class that calls this DOA method :
Code:
class ServiceDossier {

   public List<Dossier> getAll() {

      List<Object> dossiers = getIDAO().getAll();
...
      return dossiers;
   }


And this is my Facade class that calls this service :
Code:

public class FacadeDossier {

   
   public List<Dossier> getAllDossier() {
      List<Dossier> dossiers = serviceDossier.getAll();
               return dossiers;
   }


I think to surrond Facade method with the Transaction init and end. But I do not understand why it was said to me to use an interceptor for this ?

Have you use this kind of method, or have you another more used ?[/code]


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.