-->
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.  [ 8 posts ] 
Author Message
 Post subject: Deprecated config.buildSessionFactory()
PostPosted: Tue Nov 29, 2011 3:40 pm 
Newbie

Joined: Tue Nov 29, 2011 3:31 pm
Posts: 3
I am using JDK 1.7 (with Derby database), Hibernate-release-4.0.0.CR6, and Eclipse Indigo SR1. I am unable to see how I can use a non-deprecated function in this code. The problem is that the line

SessionFactory sessionFactory = config.buildSessionFactory();

gives a deprecation error for buildSessionFactory(). What alternative can I use?

-----------------------------------------------------------------------

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;

public class TestEmployee {

public static void main(String[] args) {
Configuration config = new Configuration();
config.addAnnotatedClass(Employee.class);
config.configure(); // read the file hibernate.cfg.xml

new SchemaExport(config).create(true, true);

Employee emp1 = new Employee();
Employee emp2 = new Employee();
emp1.setEmpID(150);
emp1.setEmpName("Janet Jones");
emp1.setEmpEmailAddress("Janet@songs.com");
emp2.setEmpID(250);
emp2.setEmpName("Billy Furtado");
emp2.setEmpEmailAddress("Billy@crystal.com");

SessionFactory sessionFactory = config.buildSessionFactory();
Session session = sessionFactory.openSession();
session.beginTransaction();
session.save(emp1);
session.save(emp2);
session.getTransaction().commit();
session.close();
}
}


Top
 Profile  
 
 Post subject: Re: Deprecated config.buildSessionFactory()
PostPosted: Mon Dec 19, 2011 11:36 am 
Newbie

Joined: Thu Dec 01, 2011 7:43 am
Posts: 5
I have the same issue, the method buildSessionFactory is deprecated in class Configuration.

There is not a solution in the documentation, it advises to use this deprecated method, as you can see here:

http://docs.jboss.org/hibernate/core/4. ... -xmlconfig

An alternative is needed.


Top
 Profile  
 
 Post subject: Re: Deprecated config.buildSessionFactory()
PostPosted: Sat Dec 24, 2011 6:40 am 
Newbie

Joined: Tue Nov 29, 2011 3:31 pm
Posts: 3
David you and I seem to be the only ones interested in this. Are we both making some mistake?

Someone please help!


Top
 Profile  
 
 Post subject: Re: Deprecated config.buildSessionFactory()
PostPosted: Thu Jan 05, 2012 6:45 am 
Newbie

Joined: Thu Jan 05, 2012 6:42 am
Posts: 4
i found this:

http://stackoverflow.com/questions/7986 ... ibernate-4

but still confuse...

Anyone can do a example?


Top
 Profile  
 
 Post subject: Re: Deprecated config.buildSessionFactory()
PostPosted: Thu Jan 05, 2012 9:50 am 
Newbie

Joined: Thu Dec 29, 2011 4:44 am
Posts: 3
I took the Hibernate source code and copied the code called by buildSessionFactory to my own initialization code. Maybe not a good solution, but it is a start.


Top
 Profile  
 
 Post subject: Re: Deprecated config.buildSessionFactory()
PostPosted: Sat Jan 07, 2012 9:40 am 
Newbie

Joined: Thu Jan 05, 2012 6:42 am
Posts: 4
Tested and working,

I posted a short tutorial on my site and how to configure the session under Hibernate 4...

Here is the link: http://arthurgregorio.eti.br/blog/79-programacao/java/96-buildsessionfactory-hibernate-4

(Y)


Top
 Profile  
 
 Post subject: Re: Deprecated config.buildSessionFactory()
PostPosted: Tue Jan 10, 2012 2:47 am 
Newbie

Joined: Tue Nov 29, 2011 3:31 pm
Posts: 3
Thank you for the solution gregorioarthur


Top
 Profile  
 
 Post subject: Re: Deprecated config.buildSessionFactory()
PostPosted: Fri Mar 09, 2012 2:59 am 
Newbie

Joined: Fri Mar 09, 2012 1:55 am
Posts: 1
Thank you gregorioarthur for the guide on using Hibernate 4 buildSessionFactory.


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

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.