Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Entity
- @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
- public class Problem {
- @ManyToOne
- private Person person;
- }
- @Entity
- @DiscriminatorValue("UP")
- public class UglyProblem extends Problem {}
- @Entity
- public class Person {
- @OneToMany(mappedBy="person")
- private List< UglyProblem > problems;
- }
- _____________
- |__PROBLEMS__| |__PEOPLE__|
- |id <PK> | | |
- |person <FK> | -------->| |
- |problemType | |_________ |
- --------------
- public interface Problem {
- public Person getPerson();
- }
- public interface UglyProblem extends Problem {
- }
- @MappedSuperclass
- public abstract class AbstractProblemImpl implements Problem {
- @ManyToOne
- private Person person;
- public Person getPerson() {
- return person;
- }
- }
- @Entity
- public class ProblemImpl extends AbstractProblemImpl implements Problem {
- }
- @Entity
- public class UglyProblemImpl extends AbstractProblemImpl implements UglyProblem {
- }
- public class A {
- private int foo;
- }
- @Entity
- public class B extens A {
- }
- @Entity
- public class Problem {
- @Id
- @GeneratedValue(strategy = GenerationType.AUTO)
- private Long id;
- private String name;
- public Long getId() {
- return id;
- }
- public void setId(Long id) {
- this.id = id;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- }
- @Entity
- public class UglyProblem extends Problem {
- private int levelOfUgliness;
- public int getLevelOfUgliness() {
- return levelOfUgliness;
- }
- public void setLevelOfUgliness(int levelOfUgliness) {
- this.levelOfUgliness = levelOfUgliness;
- }
- }
- CREATE TABLE "problem" (
- "DTYPE" varchar(31) NOT NULL,
- "id" bigint(20) NOT NULL auto_increment,
- "name" varchar(255) default NULL,
- "levelOfUgliness" int(11) default NULL,
- PRIMARY KEY ("id")
- ) AUTO_INCREMENT=2;
- @Entity
- @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
- @ForceDiscriminator
- public class Problem {
- }
- @Entity
- @DiscriminatorValue("UP")
- public class UglyProblem extends Problem {
- @ManyToOne
- private Person person;
- }
- @Entity
- public class Person {
- @OneToMany(mappedBy="person")
- private List< UglyProblem > problems;
- }
Add Comment
Please, Sign In to add comment