Spring Boot < == > SQL Databases

https://www.facebook.com/jpahibernate/
https://dzone.com/articles/what-is-the-difference-between-hibernate-and-sprin-1

POM.xml (maven)

<dependencies><dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependencies>
CREATE TABLE Project(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(32) NOT NULL,
description VARCHAR(512),
stage VARCHAR(32)
);
CREATE TABLE Employee (
id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
first_name VARCHAR(32) NOT NULL,
last_name VARCHAR(32),
project_id int,
FOREIGN KEY(project_id) REFERENCES Project(id)
);

Project

import javax.persistence.*;
import java.util.List;

@Entity
public class Project {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private String name;
private String stage;
private String description;

@OneToMany(mappedBy = "project")
private List<Employee> employees;

}

Employee

import javax.persistence.*;

@Entity
public class Employee {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private String firstName;
private String lastName;

@ManyToOne
@JoinColumn(name="project_id")
private Project project;
spring.datasource.url=jdbc:h2:mem:testdb
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console
spring.jpa.hibernate.ddl-auto=none

I code, I cloud, I learn

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store