0

I'm looking at example of DiscriminatorColumn at EclipseLink page.

There are two entities

@Entity
@Table(name="PROJECT")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="TYPE", discriminatorType=DiscriminatorType.STRING,length=20)
@DiscriminatorValue("P")
public class Project {

    @Id
    protected BigInteger id;
    protected String description;

}
@Entity
@DiscriminatorValue("L")
public class LargeProject extends Project {

    protected BigInteger budget;

}

now lets say i have two records in my db

| ID | TYPE |  DESCRIPTION  |  BUDGET |
|-----------|---------------|---------|
| 1  |  P   | Small Project |         |
| 2  |  L   | Large Project |  10000  |

Is it possible to drop TYPE table somehow, and use BUDGET table instead? For this case would be Project if BUDGET is null otherwise it will be LargeProject

Can JPA or EclipseLink allow to do something like that, and if not, is it any reason for that?

user902383
  • 8,420
  • 8
  • 43
  • 63
  • I doubt it, what if you change the budget of a small project so that it surpasses the threshold and becomes a large project, should it then magically change type? – Tobb Jul 29 '14 at 16:51
  • @Tobb yes, i threshold change type change as well (or if provided mapping dont allow to do that, everything blows up and throws exception) – user902383 Jul 30 '14 at 08:08
  • 1
    The answer here is what you are looking for: http://stackoverflow.com/a/22430894/496099 – Chris Jul 31 '14 at 14:56

0 Answers0