Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/nfriaa/hibernate-tutorial2

Hibernate tutorial 2 : XML Mapping
https://github.com/nfriaa/hibernate-tutorial2

hibernate hibernate5 java maven mysql xml-mapping

Last synced: about 1 hour ago
JSON representation

Hibernate tutorial 2 : XML Mapping

Awesome Lists containing this project

README

        

# hibernate-tutorial2
Hibernate XML Mapping files *(Obsolete !!! We will see in Tutorial 3 the mode "Hibernate Annotations")*

[![contributions welcome](https://img.shields.io/badge/contributions-welcome-orange.svg?style=flat)](https://github.com/nfriaa/hibernate-tutorial2/issues) [![Travis](https://img.shields.io/travis/rust-lang/rust.svg)](https://github.com/nfriaa/hibernate-tutorial2) [![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/nfriaa/hibernate-tutorial2/blob/master/LICENSE)

## Description
A sample code to execute Queries under Hibernate ORM (not directly to sql)
* JavaSE 8
* Hibernate 5
* Maven 4
* MySQL 5

## 1. Database and tables
We will use the same database and table structure in Tutorial 1

## 2. Create maven project and add dependencies
```xml

mysql
mysql-connector-java
6.0.6

org.hibernate
hibernate-core
5.2.11.Final

```

## 3. Create POJO (Plain Old Java Object) class
```java
public class Product
{
private int id;
private String name;
private int price;

// getters and setters here...
}
```
## 4. Create the XML mapping file
```xml



Add your class description here.










```

## 5. Create the hibernate config file 'hibernate.cfg.xml' (in ressources folder)
```xml


org.hibernate.dialect.MySQLDialect
jdbc:mysql://localhost:3306/persist_db?useTimezone=true&serverTimezone=UTC
root

true

```

## 6. Create HibernateUtil.java
Hibernate Utility class with a convenient method to get Session Factory.

## 7. Create main Application class
* a class whith main method to test connection
* implement CRUD operations