Skip to content

PapeMarc/Vortrag_Hibernate-ORM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hibernate ORM Tutorial

A minimal Java project demonstrating how to connect to a MySQL database using Hibernate ORM.
The sample code shows how to create a SessionFactory, persist a User entity, and cleanly shut down the session.


Prerequisites

  • JDK 8+
  • Apache Maven
  • MySQL server with a database named HibernateDB

Setup

  1. Clone the repository

    git clone https://github.com/PapeMarc/Vortrag_Hibernate-ORM.git
    cd Vortrag_Hibernate-ORM
  2. Configure database credentials
    Edit src/main/resources/hibernate.cfg.xml and insert your MySQL password:

    <property name="connection.password">{INSERT PASSWORD HERE}</property>
  3. Prepare the database
    Ensure that HibernateDB exists and contains a table user with columns:

    • id (INT, auto-increment, primary key)
    • fullname (VARCHAR)
    • pass (VARCHAR)

Build

mvn clean compile

Run

Execute the Main class (via your IDE or the command line). The sample Main program:

DatabaseAccess db = new DatabaseAccess();
db.createFactory();
db.createUser("Tim", "TimSeinSehrSicheresPasswort,!");
db.disposeFactory();

This sequence opens a session, inserts a new User record, and closes the session factory.


Project Structure

src/
 └─ main/
     ├─ java/
     │   ├─ Main.java
     │   └─ com/pape/hibernate/
     │       ├─ data/DatabaseAccess.java
     │       └─ entity/User.java
     └─ resources/
         └─ hibernate.cfg.xml

Notes

  • The project uses hibernate-core 5.6.8.Final and the MySQL Connector/J.
  • Additional CRUD operations can be added to DatabaseAccess as needed.
  • No license information is provided; treat the code as reference material.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages