Hibernate 4.3.0.Final get session

Hibernate 4.3.0.Final get session

Hi,

There seems some API change in Hibernate 4.3.0. I am not able to get the Session object in Hibernate.

I am trying to build the SessionFactory using the following piece of code:

Configuration().configure().buildSessionFactory();

I this buildSessionFactory is outdated and replaced with some other methods.

Hibernate 4.3.0.Final documentation still gives the following code for getting the session factory:

package org.hibernate.tutorial.util;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {

    private static final SessionFactory sessionFactory = buildSessionFactory();

    private static SessionFactory buildSessionFactory() {
        try {
            // Create the SessionFactory from hibernate.cfg.xml
            return new Configuration().configure().buildSessionFactory();
        }
        catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }

}

But this code is not working and it is deprecated. What is the latest method of Getting the SessionFactory?

Any help in this regard.

Thanks

View Answers

February 3, 2014 at 11:23 AM

Yes, API is deprecated and you should now use the following method of creating SessionFactory:

Configuration configuration = new Configuration();
configuration.configure();
serviceRegistry = new ServiceRegistryBuilder().applySettings(
                configuration.getProperties()).buildServiceRegistry();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);

Check the complete code at Hibernate 4 Hello World: Example of Hello World program.

Thanks









Related Tutorials/Questions & Answers:
Hibernate 4.3.0.Final get session
Hibernate 4.3.0.Final get session  Hi, There seems some API change in Hibernate 4.3.0. I am not able to get the Session object in Hibernate. I am... is outdated and replaced with some other methods. Hibernate 4.3.0.Final documentation
Hibernate Session Get
This part of discussion contain description of Hibernate session get () method
Advertisements
What are the new features of Hibernate 4.3.0.final ORM?
What are the new features of Hibernate 4.3.0.final ORM?  Hi, Can anyone tell me What are the new features of Hibernate 4.3.0.final ORM? Thanks   Hi, The most important features is its support for JPA 2.1. Hibernate
Hibernate 4.3.0.Final Maven dependency
Adding Hibernate 4.3.0.Final Maven dependency in a project How to add the Hibernate 4.3.0.Final Maven dependency in a project? The Maven is industry standard... just have to specify the dependency of Hibernate 4.3.0.Final  in your
Hibernate Session
This section contains the explanation of hibernate session
hibernate session invalid in jpa
hibernate session invalid in jpa  hibernate session invalid in jpa
Hibernate Session
In this section, you will learn about Hibernate Session
Hibernate ORM 4.3.0.Final released
Hibernate ORM 4.3.0.Final released with JPA Hibernate ORM 4.3.0 is fully JPA... 4.3.0.Final release which is JPA 2.1 compliant. This version of Hibernate...;hibernate-entitymanager</artifactId> <version>4.3.0.Final<
Hibernate Session Attribute
Hibernate Session Attribute  How can I get sub-string/int value from session.getAttribute("String"); ? I am trying to get it and my code is- Integer userCreate = (Integer) session.getAttribute ("USERID
Session interface in Hibernate
Session interface in Hibernate  Why to use Session interface in Hibernate?   It is the primary interface in Hibernate. It is a single... persistent objects. Session session = sessionFactory.openSession
Hibernate Session instances
Hibernate Session instances  Hi, Can I create multiple instances of Hibernate Session object? Thanks   Hi, Yes you can create the multiple instances of the Session object in your Hibernate application. Thanks
Get session value in javascript
Get session value in javascript   How to iterate session value onebyone in JavaScript
Session Interface in hibernate.
Session Interface in hibernate.  Define the session interface?   Hi Samar, Session interface is a single threaded object. It is the major.... It represents hibernate session, which perform the manipulation on the database
Hibernate Session Management
In this section we will discuss How to manage Hibernate session
Hibernate Session Load
This section contain description of Hibernate session load
Hibernate: Session Caching
In this section we will discuss first type of caching in Hibernate that is Session caching
Define the session factory interface in hibernate?
Define the session factory interface in hibernate?  Define the session factory interface in hibernate?   Session factory is used for manageing the session objects.public interface SessionFactory extends Referenceable
Get values from session to array
Get values from session to array  Hello I have stored my 2 dimensional array into session using C#.net. Now on aspx page i want to store same session variable into 2 dimensional array. And how to find count of session valaiable
Get values from session to array
Get values from session to array  Hello I have stored my 2 dimensional array into session using C#.net. Now on aspx page i want to store same session variable into 2 dimensional array. And how to find count of session valaiable
Why to use Session interface in Hibernate?
Why to use Session interface in Hibernate?  Why to use Session interface in Hibernate?   Session interface is defined in org.hibernate.Session. It is a single-threaded, short-lived object representing a conversation
Hibernate 4 create Session Factory: Example of creating Session Factory in Hibernate 4
Hibernate 4 create Session Factory: How to create Session Factory in Hibernate 4? In this tutorial I will explain you how you can create the Session Factory instance in your application? We are using the Hibernate 4.3.0.final build
get a session object - JSP-Servlet
get a session object  how to do in a table when i click on a radio button i should get the id value which is in the same row and store it in the session this is in jsp when in the servlet if i call a get session i have to get
How to create Hibernate session factory name?
How to create Hibernate session factory name?  Hi, I am new to Hibernate and I would like to learn how to create Hibernate Session factory name? Thanks..   HI, Here we have provided Hibernate Session factory
How do we create session factory in hibernate?
How do we create session factory in hibernate?  Hi, How do we create session factory in hibernate? thanks
Hibernate get
In this section, you will learn about get method of Hibernate
I need hibernate session factory example.
I need hibernate session factory example.  Hi, I want a simple hibernate session factory example..   hello, Here is a simple Hibernate SessionFactory Example Also go through the Hibernate 4 Thanks
session value not get in many jsp page.
session value not get in many jsp page.  I am using servlet to set session by following code :- HttpSession session=request.getSession(false...,response); and get session value on jsp page by follwing:- (adsbygoogle
Get Session Id
Get Session Id      ... in understanding Get Session Id .In this example we import a package... the information of the user. The servlet include the class Get Session Id,Inside
update count from session - Hibernate
update count from session  I need to get the count of how many rows got updated by session.saveOrUpdate(). How would I get this? Thanks, mpr
how to get session object in simple java class??
how to get session object in simple java class??  i am fallowing............................ is.................... now i need to get that session object (GroupPojo... into session. so, please tell me, how to get the session object (GroupPojo) in a simple
Maven Repository/Dependency: org.n52.sensorweb.sos | hibernate-session-factory
Maven Repository/Dependency of Group ID org.n52.sensorweb.sos and Artifact ID hibernate-session-factory. Latest version of org.n52.sensorweb.sos:hibernate-session-factory dependencies. # Version Release Date
How to use Hibernate get sessionfactory?
How to use Hibernate get sessionfactory?  Hi, How to use hibernate get sessionfactory? Thanks
Get Session Id
Get Session Id      ... the session id which was generated by the container.  HttpSession session = request.getSession(); Inside the service method we ask for the session
How many ways can we get the value of current session id?
How many ways can we get the value of current session id?  How many ways can we get the value of current session id
Session
;A servlet session is created and stored on the server side. The servlet container keeps track of all the sessions it manages and fulfills servlet API requests to get.... To the maintain the session, Web clients must pass back a valid session
How to get max date in Hibernate?
How to get max date in Hibernate?  Hi, Tell the code to get the max date in Hibernate? Thanks   Hi, You can use the projection in Hibernate for getting the max date. Here is example code: Projections.max("addmision
can pass list of n values in session and get in jsp
can pass list of n values in session and get in jsp  In dao: am... In servlet: list=userBean.selectUserBo(); HttpSession session = request.getSession...")!="") { %> i have to get value from currentUser list.and assign to a variable
can pass list of n values in session and get in jsp
can pass list of n values in session and get in jsp  In dao: am... In servlet: list=userBean.selectUserBo(); HttpSession session = request.getSession...")!="") { %> i have to get value from currentUser list.and assign to a variable
Session
Session   how to session maintaining in servlet with use of hidden fieds
session
session  is there any possibility to call one session from another session
session
session  is there any possibility to call one session from another session
session
session  Session management in Java
Hibernate Envers get all revisions
Hibernate Envers get all revisions - Example of getting all the revision of an entity In the previous example we showed you how to use the Hibernate Evers... to update entity and then show you how to get all the revisions of an entity from
Session
Session  How fined session is new or old
session
Session Management in PHP  Handling session in PHP. Can anyone please explain it with the help of an existing example about, how to handle a session while a user is logged in PHP
Session
Session   How can we set the inactivity period on a per-session basis?   We can set the session time out programmatically by using the method setMaxInactiveInterval() of HttpSession
session
session  Which methods can be invoked by the container on a stateless session bean
session
session   explain sessioln tracking in jsp and display program
Hibernate : Stateless Session
In this section we will show how stateless session works
Session
Session   hii, What Is a Session?   hello,ADS_TO_REPLACE_1 Sessions are commonly used to store temporary data to allow multiple PHP pages to offer a complete functional transaction for the same visitor

Ads