Skip to content

Instantly share code, notes, and snippets.

@madan712
Created June 29, 2019 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madan712/c875961c891af95b440192c5ba355e15 to your computer and use it in GitHub Desktop.
Save madan712/c875961c891af95b440192c5ba355e15 to your computer and use it in GitHub Desktop.
My Sql + Spring Boot JPA - One to many, many to one example
package com.javaxp.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name = "employee")
public class Employee {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "employee_id")
private Long employeeId;
@Column(name = "employee_name")
private String employeeName;
@ManyToOne
@JoinColumn(name = "department_id", nullable = false)
private Department department;
public Long getEmployeeId() {
return employeeId;
}
public void setEmployeeId(Long employeeId) {
this.employeeId = employeeId;
}
public String getEmployeeName() {
return employeeName;
}
public void setEmployeeName(String employeeName) {
this.employeeName = employeeName;
}
public Department getDepartment() {
return department;
}
public void setDepartment(Department department) {
this.department = department;
}
@Override
public String toString() {
return "Employee [employeeId=" + employeeId + ", employeeName=" + employeeName + ", department=" + department
+ "]";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment