Domanda

I am working with final hibernate version (4.3.0) & trying to create sessionFactory() instance, but it seems that everything is deprecated.

I try this:

enter image description here

And it shows, that cannot find a symbol like "buildServiceRegistry()". Also ServiceRegistryBuilder() is Deprecated. So, frankly how to instantiate it?

CODE HERE: http://pastebin.com/EkqfRxkB

È stato utile?

Soluzione

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

public class Regiutil 
{
    public static final SessionFactory sf=build();
    public static SessionFactory build()
    {
        SessionFactory s=null;
        try
        {
            s= new AnnotationConfiguration().configure().buildSessionFactory();
            return s;
        }
        catch(Throwable t)
        {

        }
        return s;
    }
    public static SessionFactory getsessionfactory()
    {
        return sf;
    }
}

and then we can use this in other file / class easily like this :

     public static Session ss=null;
     public static Transaction t= null;

    public static boolean insertdata(Loginmodel e1)
     {
         try
         {
             ss = Regiutil.getsessionfactory().openSession();
             t= ss.beginTransaction();
             ss.save(e1);
             t.commit();
             return true;
         }
         catch (Exception e) 
         {
             return false;
         }
         finally
         {
             ss.close();
         }
     }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top