Created
June 29, 2019 11:52
-
-
Save madan712/7675f2fc266d5536685ab9e41a5f42c8 to your computer and use it in GitHub Desktop.
My Sql + Spring Boot JPA - One to many, many to one example
This file contains hidden or 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 java.util.Set; | |
import javax.persistence.Column; | |
import javax.persistence.Entity; | |
import javax.persistence.GeneratedValue; | |
import javax.persistence.GenerationType; | |
import javax.persistence.Id; | |
import javax.persistence.OneToMany; | |
import javax.persistence.Table; | |
@Entity | |
@Table(name = "department") | |
public class Department { | |
@Id | |
@GeneratedValue(strategy = GenerationType.IDENTITY) | |
@Column(name = "department_id") | |
private Long departmentId; | |
@Column(name = "department_name") | |
private String departmentName; | |
@OneToMany(mappedBy = "department") | |
private Set<Employee> employeeList; | |
public Long getDepartmentId() { | |
return departmentId; | |
} | |
public void setDepartmentId(Long departmentId) { | |
this.departmentId = departmentId; | |
} | |
public String getDepartmentName() { | |
return departmentName; | |
} | |
public void setDepartmentName(String departmentName) { | |
this.departmentName = departmentName; | |
} | |
public Set<Employee> getEmployeeList() { | |
return employeeList; | |
} | |
public void setEmployeeList(Set<Employee> employeeList) { | |
this.employeeList = employeeList; | |
} | |
@Override | |
public String toString() { | |
return "Department [departmentId=" + departmentId + ", departmentName=" + departmentName +"]"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment