CodeIn House

  • Laravel
  • WordPress
  • jQuery
  • Javascript
  • Contact
Home   JAVA   How to Create Hibernate Session Factory in Spring Boot With ...

How to Create Hibernate Session Factory in Spring Boot With Configuration?

March 25, 2018 by SNK

Spring Boot and Hibernate Session Factory Configuration

Today we are going to learn how to create hibernate session factory in spring boot. Here we are going to learn how to implement hibernate session factory in spring boot with its configuration and enable support for spring boot application.

I am new to this spring boot and i am creating my new project to learn step by step. If i found any obstacle like this one, i am going to post here with its solutions.

Today i was developing modules for my project with spring boot + hibernate using maven but found that we cannot use hibernate session factory directly. So, here we are going to learn how to configure it.

I was getting following error in my console window.

spring boot session factor null pointer exception

First let me show you my directory structure of my project that i have been working on so that you will not get confused on what i am going to do below.

project directory structure

If you have seen the image, i am using repository pattern to develop my spring boot application project. As you can see in my categoryDAO.java class we need to implement session factory and was keep on getting NullPointer exception.

So to use Hibernate Session Factory we need to add this new function or line in my CategoryDAO.

CategoryDAO.java
Java
1
2
3
4
5
6
7
@Autowired
private EntityManagerFactory entityManagerFactory;
 
public Session getSession() {
   Session session = entityManagerFactory.unwrap(SessionFactory.class).openSession();
   return session;
}

After you copied above codes, you have to use getSession() in your functions in order to use hibernate session factory properties.

I have been preparing spring boot hibernate maven example with create read and update tutorial by using MySQL as an database. If you want to follow that tutorial stay tuned.

SHARE ON
Buffer

Enjoyed this article?

Like us on

JAVA Spring spring boot hibernate sessionfactory configuration

Avatar for SNK

About SNK

Hello Welcome to my Blog. I develop Websites Using Laravel Framwork & WordPress. Get Latest updates on Facebook | Twitter

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Get Connected !! With Us

TOP POSTS

  • How to Setup Spring MVC Project From Scratch in Intellij IDEA ?
  • Spring Configuration Class in JAVA [Class VS XML Config]
  • Annotations Based Configuration in Spring Framework
  • How to Configure Spring Framework with XML Configurations?
  • How to Remove Project Name from URL in JSP Project in Intellij IDEA ?

TUTORIALS TILL DATE

  • September 2022 (6)
  • June 2021 (7)
  • October 2020 (5)
  • September 2020 (6)
  • September 2018 (14)
  • August 2018 (3)
  • July 2018 (4)
  • March 2018 (8)
  • February 2018 (5)
  • January 2018 (1)
  • December 2017 (2)
  • August 2017 (8)
  • May 2017 (1)
  • April 2017 (1)
  • March 2017 (4)
  • February 2017 (3)
  • January 2017 (4)

CATEGORIES

  • Angular (2)
  • CSS3 (3)
  • D3 (3)
  • HTML5 (7)
  • JAVA (11)
  • Javascript (20)
  • jQuery (8)
  • Laravel (35)
  • Others (3)
  • PHP (11)
  • Spring (2)
  • WordPress (10)

Top Categories

  • Angular
  • CSS3
  • D3
  • HTML5
  • JAVA
  • Javascript
  • jQuery
  • Laravel
  • Others
  • PHP
  • Spring
  • WordPress

Get in Touch

DMCA.com Protection Status

Recent Articles

  • How to Setup Spring MVC Project From Scratch in Intellij IDEA ?
  • Spring Configuration Class in JAVA [Class VS XML Config]
  • Annotations Based Configuration in Spring Framework
  • How to Configure Spring Framework with XML Configurations?
  • How to Remove Project Name from URL in JSP Project in Intellij IDEA ?

© 2012-22 CodeIn House.  •  All Rights Reserved.