Created
June 29, 2019 11:51
-
-
Save madan712/c875961c891af95b440192c5ba355e15 to your computer and use it in GitHub Desktop.
My Sql + Spring Boot JPA - One to many, many to one example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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