Zdravim,

v nize uvedem kodu mi chybi ziskavani session. Bez toho nelze poradne poradit. Ale zadny z nize uvedenych prikadu mi neprijde dobry, viz komentare mezi radky.

 V jakem druhu aplikace tento kod pouzivat (web, desktop, ...)?

    Lukas



[EMAIL PROTECTED] napsal(a):
Dobrý den

Nevím zda je potřeba po každé transakci (myslím volání metody v Dao) uzavírat session. Používám Dao rozhraní s CRUD metodami.
Např.:
//##########################  TAKTO ?  ##################################

public ABO getById(int id) throws HibernateException{
                
                Student theStudent = null;              
                HibernateUtil.beginTransaction();                               
        
                theStudent = (Student) session.load(Student.class, id);
                                                                                
                return theStudent; //==========>                                
                                             
        }
V metode zahajite, ale pak neukoncite transakci!

        public void save(ABO object) throws CreateException {
HibernateUtil.beginTransaction();
                session.save(object);
session.getTransaction().commit(); }
Nad kterou session trida HibernateUtil zacne transakci, je to stejne session jako ta, nad kterou volate commit?
//##########################  NEBO TAKTO ?  ##################################

public ABO getById(int id) throws HibernateException{
                
                Student theStudent = null;              
                
               try{
                      HibernateUtil.beginTransaction();                         
        
                      theStudent = (Student) session.load(Student.class, id);

                      return theStudent; //==========>
               }finally{
                     session.close();
                }                                                               
                
       }
Co kdyz nekdo zavola tu metodu znovu? Load nad zavrenou session vzdy skonci vyjimkou.


Odpovedet emailem