[spring-data-support] Account for type hierarchy of domain types

This commit is contained in:
aboyko
2023-03-24 15:39:26 -04:00
parent 9658729f0c
commit 84ab82651f
6 changed files with 82 additions and 61 deletions

View File

@@ -8,23 +8,22 @@ import javax.persistence.Id;
import javax.persistence.ManyToOne;
@Entity
public class Customer {
public class Customer extends Person {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String firstName;
private String lastName;
private boolean thisCustomerIsSpecial;//contains keyword in name
@ManyToOne
private Employee responsibleEmployee;
protected Customer() {}
protected Customer() {
super();
}
public Customer(String firstName, String lastName, Employee responsibleEmployee) {
this.firstName = firstName;
this.lastName = lastName;
super(firstName, lastName);
this.responsibleEmployee = responsibleEmployee;
}
@@ -40,14 +39,6 @@ public class Customer {
return id;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public boolean isThisCustomerIsSpecial() {
return thisCustomerIsSpecial;
}

View File

@@ -2,25 +2,20 @@
package org.test;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class Employee {
public class Employee extends Person {
@Id
private Long socialSecurityNumber;
private String firstName;
private String lastName;
protected Employee() {
}
public Employee(long socialSecurityNumber, String firstName, String lastName) {
super(firstName, lastName);
this.socialSecurityNumber = socialSecurityNumber;
this.firstName = firstName;
this.lastName = lastName;
}
@Override
@@ -37,11 +32,4 @@ public class Employee {
return socialSecurityNumber;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
}

View File

@@ -0,0 +1,25 @@
package org.test;
public class Person {
protected String firstName;
protected String lastName;
protected Person() {
}
public Person(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
}