CRUD with Java, Hibernate and MySQL — Part 2

<!DOCTYPE hibernate-configuration PUBLIC
“-//Hibernate/Hibernate Configuration DTD 3.0//EN”">
<hibernate-configuration><session-factory> <! — allows us to get session objects for connecting to the database --><! — JDBC Database connection settings -->
<property name=”connection.driver_class”>com.mysql.jdbc.Driver</property>
<property name=”connection.url”>jdbc:mysql://localhost:3306/hb_student_tracker?useSSL=false</property>
<property name=”connection.username”>hbstudent</property>
<property name=”connection.password”>hbstudent</property>
<! — JDBC connection pool settings … using built-in test pool -->
<property name=”connection.pool_size”>1</property>
<! — Select our SQL dialect -->
<property name=”dialect”>org.hibernate.dialect.MySQLDialect</property>
<! — Echo the SQL to stdout -->
<property name=”show_sql”>true</property>
<! — Set the current session context -->
<property name=”current_session_context_class”>thread</property>

package com.luv2code.hibernate.demo.entity;import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
public class Student {

private int id;

private String firstName;

private String lastName;

private String email;
public Student(){


public Student(String firstName, String lastName, String email) {
this.firstName = firstName;
this.lastName = lastName; = email;
public int getId() {
return id;
public void setId(int id) { = id;
public String getFirstName() {
return firstName;
public void setFirstName(String firstName) {
this.firstName = firstName;
public String getLastName() {
return lastName;
public void setLastName(String lastName) {
this.lastName = lastName;
public String getEmail() {
return email;
public void setEmail(String email) { = email;
public String toString() {
return “Student [id=” + id + “, firstName=” + firstName + “, lastName=” + lastName + “, email=” + email + “]”;

Credits: The example in this article was inspired from a Spring & Hibernate For Beginners course by Chad Darby on Udemy.

Disclaimer: The aim of this article is to explain a complex topic in a short time for the reader and is in no way, shape or form intended towards discrediting the instructor’s work.


-- | Entrepreneur | Instructor | Thinker | Cloud Architect (9–5) | 3x AWS Certified | Exploring business building & digital marketing

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store