XML Mapping
- JavaSE 1.8
- Hibernate 5
- Maven 4
- MySQL 5
A sample code to execute Queries under Hibernate ORM (not directly to sql)
We will use the same database and table structure in Tutorial 1
<!-- MySQL connector --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>6.0.6</version> </dependency> <!-- Hibernate --> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>5.2.11.Final</version> </dependency> public class Product { private int id; private String name; private int price; // getters and setters here... } <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/persist_db</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password">root</property> <property name="show_sql">true</property>** <mapping file="src/main/java/net/isetjb/hibernatetutorial2/Product.hbm.xml"/> </session-factory> </hibernate-configuration> Hibernate Utility class with a convenient method to get Session Factory.
- a class whith main method to test connection
- implement CRUD operations