table structure
create table "APP".PERSON
(
ID INTEGER not null primary key,
NAME VARCHAR(256),
ADDRESS VARCHAR(256),
PHONE VARCHAR(256),
EMAIL VARCHAR(256),
TYPE VARCHAR(256)
)
person.java
import javax.persistence.*;
@Entity
@Table(name = "PERSON")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "TYPE", discriminatorType = DiscriminatorType.STRING,length=1)
public class Person implements java.io.Serializable {
@Id
@Column(name = "ID")
private int id;
@Column(name = "NAME")
private String name;
@Column(name = "ADDRESS")
private String address;
@Column(name = "PHONE")
private String phone;
@Column(name = "EMAIL")
private String email;
@Column(name = "TYPE")
private String type;
public Person() {
}
public int getId() { return id; }
public void setId(int id) { this.id = id; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public String getAddress() { return address; }
public void setAddress(String address) { this.address = address; }
public String getPhone() { return phone; }
public void setPhone(String phone) { this.phone = phone; }
public String getEmail() { return email; }
public void setEmail(String email) { this.email = email; }
public String getType() { return type; }
public void setType(String type) { this.type = type; }
}
student.java
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
@Entity
@DiscriminatorValue(value="S")
public class Student extends Person {
public Student() {
}
}
employee.java
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;@Entity
@DiscriminatorValue(value="E")
public class Employee extends Person{
public Employee() {
}
}
No comments:
Post a Comment