Commit 861f7763 by Patryk Czarnik

Zmiany w wygenerowanych klasach

parent 5af14f61
package hr.model;
/** Wspólna nadklasa dla wszystkich klas encji w tym pakiecie. Miejsce na dodatkowe metody. */
abstract class AbstractEntity {
public String hello() {
return "hello";
}
}
...@@ -4,7 +4,7 @@ import jakarta.persistence.*; ...@@ -4,7 +4,7 @@ import jakarta.persistence.*;
@Entity @Entity
@Table(name = "countries") @Table(name = "countries")
public class Country { public class Country extends AbstractEntity {
@Id @Id
@Column(name = "country_id", nullable = false, length = 2) @Column(name = "country_id", nullable = false, length = 2)
private String countryId; private String countryId;
......
...@@ -8,7 +8,7 @@ import java.util.Set; ...@@ -8,7 +8,7 @@ import java.util.Set;
@Entity @Entity
@Table(name = "departments") @Table(name = "departments")
public class Department { public class Department extends AbstractEntity {
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@ColumnDefault("nextval('departments_seq')") @ColumnDefault("nextval('departments_seq')")
...@@ -26,7 +26,7 @@ public class Department { ...@@ -26,7 +26,7 @@ public class Department {
private hr.model.Location location; private hr.model.Location location;
@OneToMany(mappedBy = "department") @OneToMany(mappedBy = "department")
private Set<Integer> employees = new LinkedHashSet<>(); private Set<Employee> employees = new LinkedHashSet<>();
public Integer getId() { public Integer getId() {
return id; return id;
...@@ -60,11 +60,11 @@ public class Department { ...@@ -60,11 +60,11 @@ public class Department {
this.location = location; this.location = location;
} }
public Set<Integer> getEmployees() { public Set<Employee> getEmployees() {
return employees; return employees;
} }
public void setEmployees(Set<Integer> employees) { public void setEmployees(Set<Employee> employees) {
this.employees = employees; this.employees = employees;
} }
......
...@@ -7,7 +7,7 @@ import java.time.LocalDate; ...@@ -7,7 +7,7 @@ import java.time.LocalDate;
@Entity @Entity
@Table(name = "employees") @Table(name = "employees")
public class Employee { public class Employee extends AbstractEntity {
@Id @Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "employees_id_gen") @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "employees_id_gen")
@SequenceGenerator(name = "employees_id_gen", sequenceName = "employees_seq", initialValue = 207, allocationSize = 1) @SequenceGenerator(name = "employees_id_gen", sequenceName = "employees_seq", initialValue = 207, allocationSize = 1)
......
...@@ -8,9 +8,8 @@ import java.util.Set; ...@@ -8,9 +8,8 @@ import java.util.Set;
@Entity @Entity
@Table(name = "jobs") @Table(name = "jobs")
public class Job { public class Job extends AbstractEntity {
@Id @Id
@SequenceGenerator(name = "jobs_id_gen", sequenceName = "employees_seq", initialValue = 207, allocationSize = 1)
@Column(name = "job_id", nullable = false, length = 10) @Column(name = "job_id", nullable = false, length = 10)
private String jobId; private String jobId;
...@@ -24,7 +23,7 @@ public class Job { ...@@ -24,7 +23,7 @@ public class Job {
private BigDecimal maxSalary; private BigDecimal maxSalary;
@OneToMany(mappedBy = "job") @OneToMany(mappedBy = "job")
private Set<Integer> employees = new LinkedHashSet<>(); private Set<Employee> employees = new LinkedHashSet<>();
public String getJobId() { public String getJobId() {
return jobId; return jobId;
...@@ -58,11 +57,11 @@ public class Job { ...@@ -58,11 +57,11 @@ public class Job {
this.maxSalary = maxSalary; this.maxSalary = maxSalary;
} }
public Set<Integer> getEmployees() { public Set<Employee> getEmployees() {
return employees; return employees;
} }
public void setEmployees(Set<Integer> employees) { public void setEmployees(Set<Employee> employees) {
this.employees = employees; this.employees = employees;
} }
......
...@@ -6,22 +6,21 @@ import java.time.LocalDate; ...@@ -6,22 +6,21 @@ import java.time.LocalDate;
@Entity @Entity
@Table(name = "job_history") @Table(name = "job_history")
public class JobHistory { public class JobHistory extends AbstractEntity {
@SequenceGenerator(name = "job_history_id_gen", sequenceName = "employees_seq", initialValue = 207, allocationSize = 1)
@EmbeddedId @EmbeddedId
private JobHistoryId id; private JobHistoryId id;
@MapsId("employeeId") @MapsId("employeeId")
@ManyToOne(fetch = FetchType.LAZY, optional = false) @ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "employee_id", nullable = false) @JoinColumn(name = "employee_id", nullable = false)
private Integer employee; private Employee employee;
@Column(name = "end_date", nullable = false) @Column(name = "end_date", nullable = false)
private LocalDate endDate; private LocalDate endDate;
@ManyToOne(fetch = FetchType.LAZY, optional = false) @ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "job_id", nullable = false) @JoinColumn(name = "job_id", nullable = false)
private hr.model.Job job; private Job job;
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "department_id") @JoinColumn(name = "department_id")
...@@ -35,11 +34,11 @@ public class JobHistory { ...@@ -35,11 +34,11 @@ public class JobHistory {
this.id = id; this.id = id;
} }
public Integer getEmployee() { public Employee getEmployee() {
return employee; return employee;
} }
public void setEmployee(Integer employee) { public void setEmployee(Employee employee) {
this.employee = employee; this.employee = employee;
} }
...@@ -51,11 +50,11 @@ public class JobHistory { ...@@ -51,11 +50,11 @@ public class JobHistory {
this.endDate = endDate; this.endDate = endDate;
} }
public hr.model.Job getJob() { public Job getJob() {
return job; return job;
} }
public void setJob(hr.model.Job job) { public void setJob(Job job) {
this.job = job; this.job = job;
} }
......
...@@ -5,7 +5,7 @@ import org.hibernate.annotations.ColumnDefault; ...@@ -5,7 +5,7 @@ import org.hibernate.annotations.ColumnDefault;
@Entity @Entity
@Table(name = "locations") @Table(name = "locations")
public class Location { public class Location extends AbstractEntity {
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@ColumnDefault("nextval('locations_seq')") @ColumnDefault("nextval('locations_seq')")
......
...@@ -7,7 +7,7 @@ import jakarta.persistence.Table; ...@@ -7,7 +7,7 @@ import jakarta.persistence.Table;
@Entity @Entity
@Table(name = "regions") @Table(name = "regions")
public class Region { public class Region extends AbstractEntity {
@Id @Id
@Column(name = "region_id", nullable = false) @Column(name = "region_id", nullable = false)
private Integer id; private Integer id;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment