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: 13 days ago
JSON representation
Hibernate tutorial 2 : XML Mapping
- Host: GitHub
- URL: https://github.com/nfriaa/hibernate-tutorial2
- Owner: nfriaa
- License: mit
- Created: 2017-10-02T11:16:26.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-18T17:37:58.000Z (about 8 years ago)
- Last Synced: 2025-07-19T23:26:10.035Z (4 months ago)
- Topics: hibernate, hibernate5, java, maven, mysql, xml-mapping
- Language: Java
- Size: 18.6 KB
- Stars: 0
- Watchers: 0
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hibernate-tutorial2
Hibernate XML Mapping files *(Obsolete !!! We will see in Tutorial 3 the mode "Hibernate Annotations")*
[](https://github.com/nfriaa/hibernate-tutorial2/issues) [](https://github.com/nfriaa/hibernate-tutorial2) [](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