JPA using Hibernate and mysql in Netbeans 8.1
General steps taken in the video above.(Not the exact steps)
- Create database jpa_1:
create database jpa_1; |
- Configure Netbeans 8.1 to have the database in services:
Database: jpa_1 url: jdbc:mysql://localhost:3306/jpa_1 username: greenhorn |
- Create a maven java application in Netbeans 8.1.
- Add maven dependencies into pom.xml:
<dependencies> <!– for JPA, use hibernate-entitymanager instead of hibernate-core –> <dependency> <dependency> </dependencies> |
- Add class, Book.java from Netbeans “New” right click option. Includes the below instance variable.
private String name; |
- Add class, Student.java from Netbeans “New” right click option. Includes the below instance variables.
private String firstName; private String lastName; @OneToMany(cascade = CascadeType.ALL) |
- Generate getter and setter methods for the instance variables in Student and Book class from Netbeans.
- Add class, Main.java from Netbeans “New” right click option. Includes the below main method.
public static void main(String[] args) { |
- Clean the pom file. It should look similar to the below:
<modelVersion>4.0.0</modelVersion> <dependencies> <!-- for JPA, use hibernate-entitymanager instead of hibernate-core --> <dependency> <dependency> |
- Run Main class from Netbeans 8.1
NOTE The sample maven project used for this exercise can be downloaded from |
---|