| | |
| | | package de.gedoplan.seminar.jpa.exercise.domain; |
| | | |
| | | import java.util.HashSet; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.Stream; |
| | | |
| | | import javax.persistence.Entity; |
| | | import javax.persistence.JoinColumn; |
| | | import javax.persistence.JoinTable; |
| | | import javax.persistence.ManyToMany; |
| | | import javax.persistence.Table; |
| | | |
| | | import de.gedoplan.seminar.jpa.exercise.common.GeneratedIntegerIdEntity; |
| | |
| | | @Entity |
| | | @Table(name = MaintenanceDepartment.TABLE_NAME) |
| | | public class MaintenanceDepartment extends GeneratedIntegerIdEntity { |
| | | public static final String TABLE_NAME = "JPA_MAINTENANCE_DEPT"; |
| | | public static final String TABLE_NAME_HIGHWAYS = "JPA_MAINTENANCE_DEPT_HIGHWAY"; |
| | | public static final String TABLE_NAME = "JPA_MAINTENANCE_DEPT"; |
| | | public static final String TABLE_NAME_HIGHWAYS = "JPA_MAINTENANCE_DEPT_HIGHWAY"; |
| | | |
| | | private String name; |
| | | private String name; |
| | | |
| | | @ManyToMany |
| | | @JoinTable(name = TABLE_NAME_HIGHWAYS, joinColumns = @JoinColumn(name = "MAINTENANCE_DEPT_ID"), inverseJoinColumns = @JoinColumn(name = "HIGHWAY_ID")) |
| | | private Set<Highway> highways = new HashSet<>(); |
| | | |
| | | protected MaintenanceDepartment() { |
| | | } |
| | | protected MaintenanceDepartment() { |
| | | } |
| | | |
| | | public MaintenanceDepartment(String name, Highway... highways) { |
| | | this.name = name; |
| | | } |
| | | public MaintenanceDepartment(String name, Highway... highways) { |
| | | this.name = name; |
| | | this.highways = Stream.of(highways).collect(Collectors.toSet()); |
| | | } |
| | | |
| | | public String getName() { |
| | | return this.name; |
| | | } |
| | | public String getName() { |
| | | return this.name; |
| | | } |
| | | |
| | | public Set<Highway> getHighways() { |
| | | return highways; |
| | | } |
| | | |
| | | public void setName(String name) { |
| | | this.name = name; |
| | | } |
| | | |
| | | } |