@Inheritance(strategy = InheritanceType.JOINED)
The option here is
- SINGLE_TABLE
- TABLE_PER_CLASS
- JOINED
SINGLE_TABLE

TABLE_PER_CLASS

JOINED

To persist animal:
em.persist(new Animal(1,"honey"));Openjpa will generate the sql below
INSERT INTO Animal (id, name) VALUES (1, 'honey')
To persist fish:
em.persist(new Fish(2,"mermaid","SEA"));Openjpa will generate the sql below
INSERT INTO Animal (id, name) VALUES (2, 'mermaid')
INSERT INTO Fish (id, territory) VALUES (2, 'SEA')
To query animal:
em2.createQuery("select m from Animal m").getResultList();Openjpa will generate the sql below
SELECT t0.id, t1.id, t2.id, t0.name, t1.sex, t2.territoryOpenjpa will map the result to Fish or Dog object automatically.
FROM Animal t0
LEFT OUTER JOIN Dog t1 ON t0.id = t1.id
LEFT OUTER JOIN Fish t2 ON t0.id = t2.id
To query fish:
em2.createQuery("select fish from Fish fish").getResultList();Openjpa will generate the sql below
SELECT t1.id, t0.id, t1.name, t0.territoryOpenjpa will map the the result to Fish object.
FROM Fish t0
INNER JOIN Animal t1 ON t0.id = t1.id
No comments:
Post a Comment