Friday, June 15, 2018

Simple Springboot + hibernate + mysql example

This is a simple spring boot + hibernate (JPA) example.

Below are the tables created in MySQL

create table category
(
catid int not null auto_increment,primary key (catid),
catname  varchar(30) not null
);


create table menu
(
menuid int not null auto_increment, primary key (menuid),
menuname varchar(60) not null,
catid int not null, 
        foreign key (catid) references category(catid)

);


Here is the pom.xml file



These are the two corresponding model classes -

Menu.java


Category.java


This is the application.properties file


This is the main class of SpringBoot Application - App.java


This is the configuration class where SessionFactory and DataSource are configured


This is the Service class showing how to connect to database using sessionfactory