Showing posts with label JPA Inheritance Strategies. Show all posts
Showing posts with label JPA Inheritance Strategies. Show all posts

Monday, 19 August 2013

Inheritance Mapping Stategies in JPA

In JPA, an entity class may inherit from another entity class its behavior and state. The behavior and state become shared between entity classes enabling the inheritance of existing mappings. There are several types of inheritance which are  Joined Strategy, Single-Table Strategy, Table-per-Concrete-Class Strategy. Two of these types; Single table inheritance and Joined table inheritance have many similarities:

When it comes to mapping inheritance, JPA supports three different strategies. When an entity hierarchy exists, it always has an entity as its root. The root entity class can define the inheritance strategy by using the @Inheritance annotation. If it doesn’t, the default single-table-per-class strategy will be applied.

Their object model is the same.
  • They can be configured using either annotations or XML.
  • A discriminator column (a single column used for distinguishing to which class type a database row belongs) is required on the database.
  • The underlying database structure of the single table and joined table inheritance is, however, slightly different.
please refer to each type link for further discussion, example and code snippts.

Joined Strategy

In the joined table inheritance, each class shares data from the root table. In addition, each subclass defines its own table that adds its extended state. The following example shows two child tables, EXTERNAT_VET and IN_HOUSE_VET, as well as parent table VET.
Click here for mode details about Joined Strategy

Single-Table Strategy

In the single table inheritance, the entire class hierarchy is represented by a single table. As the following example shows, the Three classes map to the same VET_ALL table.
Click here for mode details about Single Table Strategy


Table-per-Concrete-Class Strategy

In the table-per-concrete class, each Table contains the shared data as its specific data. In addition, each subclass defines its own table that adds its extended state. The following example shows two child tables, VET_IN and VET_OUT.
Click here for mode details about Table-per-Concrete Class Strategy

JPA Table-Per-Concrete Strategy

In the table-per-class (or table-per-concrete-class) strategy, each entity is mapped to its own dedicated table like the joined strategy. The difference is that all attributes of the root entity will also be mapped to columns of the child entity table. From a database point of view, this strategy de-normalizes the model and causes all root entity attributes to be redefined in the tables of all leaf entities that inherit from it. With the table-per-class strategy, there is no shared table, no shared columns, and no discriminator column. The only requirement is that all tables must share a common primary key that matches across all tables in the hierarchy.

In the table-per-concrete class, each Table contains the shared data as its specific data. In addition, each subclass defines its own table that adds its extended state. The following example shows two child tables, VET_IN and VET_OUT

TABLE CREATION:


VET_IN Table
CREATE TABLE VET_IN 
(
VET_ID NUMBER NOT NULL
, NAME VARCHAR2(45 BYTE)
, QUALIFICATION VARCHAR2(45 BYTE)
, SALARY NUMBER
, CONSTRAINT VET_IN_PK PRIMARY KEY
(
VET_ID
)
ENABLE
);

VET_OUT Table
CREATE TABLE VET_OUT 
(
VET_ID NUMBER NOT NULL
, NAME VARCHAR2(45 BYTE)
, COUNTRY VARCHAR2(45 BYTE)
, VISITING_FEES NUMBER
, QUALIFICATION VARCHAR2(45 BYTE)
, CONSTRAINT VET_OUT_PK PRIMARY KEY
(
VET_ID
)
ENABLE
);

SEQUENCES AND TRIGGERS CREATION:


Table VET_IN Sequence and Trigger
CREATE SEQUENCE VET_IN_SEQ NOCACHE;

create or replace TRIGGER VET_IN_TRG
BEFORE INSERT ON VET_IN
FOR EACH ROW
BEGIN
IF :NEW.VET_ID IS NULL THEN
SELECT VET_IN_SEQ.NEXTVAL INTO :NEW.VET_ID FROM DUAL;
END IF;
END;

Table VET_OUT Sequence and Trigger
CREATE SEQUENCE VET_OUT_SEQ NOCACHE;

create or replace TRIGGER VET_OUT_TRG
BEFORE INSERT ON VET_OUT
FOR EACH ROW
BEGIN
IF :NEW.VET_ID IS NULL THEN
SELECT VET_OUT_SEQ.NEXTVAL INTO :NEW.VET_ID FROM DUAL;
END IF;
end;

INSERT TEST DATA:


inserting into VET_IN
REM INSERTING into VET_IN
Insert into VET_IN (VET_ID,NAME,QUALIFICATION,SALARY) values (1,'Ashitraj more','mvsc',35000);
Insert into VET_IN (VET_ID,NAME,QUALIFICATION,SALARY) values (2,'Raj','bvsc',30000);
Insert into VET_IN (VET_ID,NAME,QUALIFICATION,SALARY) values (4,'Rakesh','mvsc',29000);

inserting into VET_OUT
REM INSERTING into VET_OUT
Insert into VET_OUT (VET_ID,NAME,COUNTRY,VISITING_FEES,QUALIFICATION) values (3,'Steven','UK',500,'mvsc');
Insert into VET_OUT (VET_ID,NAME,COUNTRY,VISITING_FEES,QUALIFICATION) values (5,'John','US',450,'mvsc');

CLASS CREATION:


ConcreteVet Class
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class ConcreteVet implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@Basic(optional = false)
@Column(name = "VET_ID")
private Integer vetId;
@Column(name = "NAME")
private String name;
@Column(name = "QUALIFICATION")
private String qualification;
//generate getters, setters, toString(), hashCode(),equals()
}

ConcreteInVet Class
@Entity
@Table(name = "VET_IN")
public class ConcreteInVet extends ConcreteVet{

@Column(name = "SALARY")
private Integer salary;
//generate getters, setters, toString(), hashCode(),equals()
}

ConcreteOutVet Class
@Entity
@Table(name = "VET_OUT")
public class ConcreteOutVet extends ConcreteVet{

@Column(name = "COUNTRY")
private String country;
@Column(name = "VISITING_FEES")
private Integer visitingFees;
//generate getters, setters, toString(), hashCode(),equals()

}

JUNIT TEST CASE:

public class InheritanceJUnit {

static EntityManagerFactory emf;
static EntityManager em;
static EntityTransaction trx;

@BeforeClass
public static void initEntityManager() throws Exception {
emf = Persistence.createEntityManagerFactory("JavaApplicationJPAPU");
em = emf.createEntityManager();
trx = em.getTransaction();
}

@AfterClass
public static void closeEntityManager() throws Exception {
em.close();
emf.close();
}

@Before
public void initTransaction() throws Exception {
trx.begin();
}

@After
public void endTransaction() throws Exception {
if (!trx.getRollbackOnly()) {
trx.commit();
}
}
@Test
@Ignore
public void testConcreteStrategyInsert() {

ConcreteInVet inVet = new ConcreteInVet();
inVet.setName("Invet name 10");
inVet.setQualification("invet Qualification 10");
inVet.setSalary(1010);
inVet.setVetId(10);
em.persist(inVet);
System.out.println("InHouseVet inserted");

ConcreteOutVet extVet = new ConcreteOutVet();
extVet.setName("extVet name 11");
extVet.setQualification("extVet Qualification 11");
extVet.setCountry("xy");
extVet.setVisitingFees(1111);
extVet.setVetId(11);
em.persist(extVet);
System.out.println("ExternatVet inserted");
}

@Test
@Ignore
public void testConcreteStrategySelect() {

ConcreteVet vet = em.find(ConcreteVet.class, 10);
assertNotNull(vet);

if (vet instanceof ConcreteInVet) {
ConcreteInVet concreteInVet = (ConcreteInVet) vet;
System.out.println(concreteInVet);
} else if (vet instanceof ConcreteOutVet) {
ConcreteOutVet concreteOutVet = (ConcreteOutVet) vet;
System.out.println(concreteOutVet);
} else {
System.out.println("ERROR in Type");
}

ConcreteVet vet2 = em.find(ConcreteVet.class, 11);
assertNotNull(vet2);

if (vet2 instanceof ConcreteInVet) {
ConcreteInVet concreteInVet = (ConcreteInVet) vet2;
System.out.println(concreteInVet);
} else if (vet2 instanceof ConcreteOutVet) {
ConcreteOutVet concreteOutVet = (ConcreteOutVet) vet2;
System.out.println(concreteOutVet);
} else {
System.out.println("ERROR in Type");
}

}

@Test
@Ignore
public void testConcreteStrategyUpdate() {

ConcreteVet vet = em.find(ConcreteVet.class, 10);
assertNotNull(vet);

if (vet instanceof ConcreteOutVet) {
ConcreteOutVet concreteOutVet = (ConcreteOutVet) vet;
concreteOutVet.setName("extVet Qualification 10 updated");
concreteOutVet.setVisitingFees(101010);
em.merge(concreteOutVet);
System.out.println(concreteOutVet);
} else if (vet instanceof ConcreteInVet) {
ConcreteInVet concreteInVet = (ConcreteInVet) vet;
concreteInVet.setName("Invet name 10 updated");
concreteInVet.setSalary(1111);
em.merge(concreteInVet);
System.out.println(concreteInVet);
} else {
System.out.println("ERROR in Type");
}

ConcreteVet vet2 = em.find(ConcreteVet.class, 11);
assertNotNull(vet2);

if (vet2 instanceof ConcreteOutVet) {
ConcreteOutVet concreteOutVet = (ConcreteOutVet) vet2;
concreteOutVet.setName("extVet Qualification 11 updated");
concreteOutVet.setVisitingFees(101010);
em.merge(concreteOutVet);
System.out.println(concreteOutVet);
} else if (vet2 instanceof ConcreteInVet) {
ConcreteInVet concreteInVet = (ConcreteInVet) vet2;
concreteInVet.setName("extVet name 11 updated");
concreteInVet.setSalary(1111);
em.merge(concreteInVet);
System.out.println(concreteInVet);
} else {
System.out.println("ERROR in Type");
}


}

@Test
@Ignore
public void testConcreteStrategyDelete() {

ConcreteVet vet = em.find(ConcreteVet.class, 10);
assertNotNull(vet);
em.remove(vet);
System.out.println("InHouseVet 10 : deleteds");

ConcreteVet vet2 = em.find(ConcreteVet.class, 11);
assertNotNull(vet2);

if (vet2 instanceof ConcreteOutVet) {
ConcreteOutVet concreteOutVet = (ConcreteOutVet) vet2;
em.remove(concreteOutVet);
System.out.println("ExternatVet 11 : deleted");
} else if (vet2 instanceof ConcreteInVet) {
ConcreteInVet concreteInVet = (ConcreteInVet) vet2;
em.remove(concreteInVet);
System.out.println("InHouseVet 11 : deleteds");
} else {
System.out.println("ERROR in Type");
}
}
}


Sunday, 18 August 2013

JPA Single Table Strategy

The default inheritance mapping strategy is the single-table strategy, in which all the entities in the hierarchy are mapped to a single table. As it is the default, you can completely omit the @Inheritance annotation on the root entity (thanks to configuration by exception).
In the single table inheritance, the entire class hierarchy is represented by a single table. As the following example shows, the Three classes map to the same VET_ALL table

TABLE CREATION:

CREATE TABLE VET_ALL 
(
VET_ID NUMBER NOT NULL
, NAME VARCHAR2(45 BYTE)
, QUALIFICATION VARCHAR2(45 BYTE)
, SALARY NUMBER
, COUNTRY VARCHAR2(45 BYTE)
, VISITING_FEES NUMBER
, VET_TYPE VARCHAR2(10 BYTE)
, CONSTRAINT VET_ALL_PK PRIMARY KEY
(
VET_ID
)
ENABLE
);

SEQUENCES AND TRIGGERS CREATION:

CREATE SEQUENCE VET_ALL_SEQ NOCACHE;

create or replace TRIGGER VET_ALL_TRG
BEFORE INSERT ON VET_ALL
FOR EACH ROW
BEGIN
IF :NEW.VET_ID IS NULL THEN
SELECT VET_ALL_SEQ.NEXTVAL INTO :NEW.VET_ID FROM DUAL;
END IF;
END;


INSERT TEST DATA:

REM INSERTING into VET_ALL
Insert into VET_ALL (VET_ID,NAME,QUALIFICATION,SALARY,COUNTRY,VISITING_FEES,VET_TYPE) values (1,'Ashitraj more','mvsc',35000,null,null,'IN_VET9');
Insert into VET_ALL (VET_ID,NAME,QUALIFICATION,SALARY,COUNTRY,VISITING_FEES,VET_TYPE) values (2,'Raj','bvsc',30000,null,null,'IN_VET');
Insert into VET_ALL (VET_ID,NAME,QUALIFICATION,SALARY,COUNTRY,VISITING_FEES,VET_TYPE) values (4,'Rakesh','mvsc',29000,null,null,'IN_VET');
Insert into VET_ALL (VET_ID,NAME,QUALIFICATION,SALARY,COUNTRY,VISITING_FEES,VET_TYPE) values (5,'John','mvsc',null,'US',450,'EXT_VET');
Insert into VET_ALL (VET_ID,NAME,QUALIFICATION,SALARY,COUNTRY,VISITING_FEES,VET_TYPE) values (3,'Steven','mvsc',null,'UK',500,'EXT_VET');

CLASS CREATION:


SingleVet Class
@Entity
@Table(name = "VET_ALL")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "VET_TYPE")
public abstract class SingleVet implements Serializable {

private static final long serialVersionUID = 1L;

@Id
@Basic(optional = false)
@Column(name = "VET_ID")
private Integer vetId;
@Column(name = "NAME")
private String name;
@Column(name = "QUALIFICATION")
private String qualification;
//generate getters, setters, toString(), hashCode(),equals()
}

SingleOutVet Class
@Entity
@DiscriminatorValue("EXT_VET")
public class SingleOutVet extends SingleVet{

@Column(name = "COUNTRY")
private String country;
@Column(name = "VISITING_FEES")
private Integer visitingFees;
//generate getters, setters, toString(), hashCode(),equals()
}

SingleInVet Class
@Entity
@DiscriminatorValue("IN_VET")
public class SingleInVet extends SingleVet{

@Column(name = "SALARY")
private Integer salary;
//generate getters, setters, toString(), hashCode(),equals()
}

JUNIT TEST CASE:

public class InheritanceJUnit {

static EntityManagerFactory emf;
static EntityManager em;
static EntityTransaction trx;

@BeforeClass
public static void initEntityManager() throws Exception {
emf = Persistence.createEntityManagerFactory("JavaApplicationJPAPU");
em = emf.createEntityManager();
trx = em.getTransaction();
}

@AfterClass
public static void closeEntityManager() throws Exception {
em.close();
emf.close();
}

@Before
public void initTransaction() throws Exception {
trx.begin();
}

@After
public void endTransaction() throws Exception {
if (!trx.getRollbackOnly()) {
trx.commit();
}
}

@Test
@Ignore
public void testSingleStrategyInsert() {

SingleInVet inVet = new SingleInVet();
inVet.setName("Invet name 10");
inVet.setQualification("invet Qualification 10");
inVet.setSalary(1010);
inVet.setVetId(10);
em.persist(inVet);
System.out.println("InHouseVet inserted");

SingleOutVet extVet = new SingleOutVet();
extVet.setName("extVet name 11");
extVet.setQualification("extVet Qualification 11");
extVet.setCountry("xy");
extVet.setVisitingFees(1111);
extVet.setVetId(11);
em.persist(extVet);
System.out.println("ExternatVet inserted");
}

@Test
@Ignore
public void testSingleStrategySelect() {
SingleVet vet = em.find(SingleVet.class, 10);
assertNotNull(vet);

if (vet instanceof SingleOutVet) {
SingleOutVet singleOutVet = (SingleOutVet) vet;
System.out.println(singleOutVet);
} else if (vet instanceof SingleInVet) {
SingleInVet singleInVet = (SingleInVet) vet;
System.out.println(singleInVet);
} else {
System.out.println("ERROR in Type");
}

SingleVet vet2 = em.find(SingleVet.class, 11);
assertNotNull(vet2);

if (vet2 instanceof SingleOutVet) {
SingleOutVet singleOutVet = (SingleOutVet) vet2;
System.out.println(singleOutVet);
} else if (vet2 instanceof SingleInVet) {
SingleInVet singleInVet = (SingleInVet) vet2;
System.out.println(singleInVet);
} else {
System.out.println("ERROR in Type");
}

}

@Test
@Ignore
public void testSingleStrategyUpdate() {

SingleVet vet = em.find(SingleVet.class, 10);
assertNotNull(vet);

if (vet instanceof SingleOutVet) {
SingleOutVet SingleOutVet = (SingleOutVet) vet;
SingleOutVet.setName("extVet Qualification 11 updated");
SingleOutVet.setVisitingFees(101010);
em.merge(SingleOutVet);
System.out.println(SingleOutVet);
} else if (vet instanceof SingleInVet) {
SingleInVet SingleInVet = (SingleInVet) vet;
SingleInVet.setName("Invet name 10 updated");
SingleInVet.setSalary(1010);
em.merge(SingleInVet);
System.out.println(SingleInVet);
} else {
System.out.println("ERROR in Type");
}

SingleVet vet2 = em.find(SingleVet.class, 11);
assertNotNull(vet2);

if (vet2 instanceof SingleOutVet) {
SingleOutVet SingleOutVet = (SingleOutVet) vet2;
SingleOutVet.setName("extVet Qualification 11 updated");
SingleOutVet.setVisitingFees(111111);
em.merge(SingleOutVet);
System.out.println(SingleOutVet);
} else if (vet2 instanceof SingleInVet) {
SingleInVet SingleInVet = (SingleInVet) vet2;
SingleInVet.setName("Invet name 11 updated");
SingleInVet.setSalary(1111);
em.merge(SingleInVet);
System.out.println(SingleInVet);
} else {
System.out.println("ERROR in Type");
}
}

@Test
@Ignore
public void testSingleStrategyDelete() {

SingleVet vet = em.find(SingleVet.class, 10);
assertNotNull(vet);
em.remove(vet);
System.out.println("InHouseVet 10 : deleteds");

SingleVet vet2 = em.find(SingleVet.class, 11);
assertNotNull(vet2);
if (vet2 instanceof SingleOutVet) {
SingleOutVet singleOutVet = (SingleOutVet) vet2;
em.remove(singleOutVet);
System.out.println("ExternatVet 11 : deleted");
} else if (vet2 instanceof SingleInVet) {
SingleInVet singleInVet = (SingleInVet) vet2;
em.remove(singleInVet);
System.out.println("InHouseVet 11 : deleteds");
} else {
System.out.println("ERROR in Type");
}
}

}

JPA Joined Strategy

In the joined strategy, each entity in the hierarchy is mapped to its own table. The root entity maps to a table that defines the primary key to be used by all tables in the hierarchy, as well as the discriminator column. Each subclass is represented by a separate table that contains its own attributes (not inherited from the root class) and a primary key that refers to the root table’s primary key. The non-root tables do not hold a discriminator column.

In the joined table inheritance, each class shares data from the root table. In addition, each subclass defines its own table that adds its extended state. The following example shows two child tables, EXTERNAT_VET and IN_HOUSE_VET, as well as parent table VET:


Table Creation:


VET table
CREATE TABLE VET 
(
VET_ID NUMBER NOT NULL
, NAME VARCHAR2(45 BYTE)
, QUALIFICATION VARCHAR2(45 BYTE)
, VET_TYPE VARCHAR2(10 BYTE)
, CONSTRAINT VET_PK PRIMARY KEY
(
VET_ID
)
ENABLE
);

EXTERNAT_VET  table
CREATE TABLE EXTERNAT_VET 
(
VET_ID NUMBER NOT NULL
, COUNTRY VARCHAR2(45 BYTE)
, VISITING_FEES NUMBER
, CONSTRAINT EXTERNAT_VET_PK PRIMARY KEY
(
VET_ID
)
ENABLE
);

IN_HOUSE_VET table
CREATE TABLE IN_HOUSE_VET 
(
VET_ID NUMBER NOT NULL
, SALARY NUMBER
, CONSTRAINT IN_HOUSE_VET_PK PRIMARY KEY
(
VET_ID
)
ENABLE
);

Sequences and Triggers Creation:

CREATE SEQUENCE VET_SEQ NOCACHE;

create or replace TRIGGER VET_TRG
BEFORE INSERT ON VET
FOR EACH ROW
BEGIN
IF :NEW.VET_ID IS NULL THEN
SELECT VET_SEQ.NEXTVAL INTO :NEW.VET_ID FROM DUAL;
END IF;
END;
/

Insert Test Data:

VET table
REM INSERTING into VET
Insert into VET (VET_ID,NAME,QUALIFICATION,VET_TYPE) values (1,'Ashitraj more','mvsc','IN_VET');
Insert into VET (VET_ID,NAME,QUALIFICATION,VET_TYPE) values (2,'Raj','bvsc','IN_VET');
Insert into VET (VET_ID,NAME,QUALIFICATION,VET_TYPE) values (3,'Steven','mvsc','EXT_VET');
Insert into VET (VET_ID,NAME,QUALIFICATION,VET_TYPE) values (4,'Rakesh','mvsc','IN_VET');
Insert into VET (VET_ID,NAME,QUALIFICATION,VET_TYPE) values (5,'John','mvsc','EXT_VET');
Insert into VET (VET_ID,NAME,QUALIFICATION,VET_TYPE) values (6,'vet','vet qualification','VET');

EXTERNAT_VET  table
REM INSERTING into EXTERNAT_VET
Insert into EXTERNAT_VET (VET_ID,COUNTRY,VISITING_FEES) values (3,'UK',500);
Insert into EXTERNAT_VET (VET_ID,COUNTRY,VISITING_FEES) values (5,'US',450);

IN_HOUSE_VET table
REM INSERTING into IN_HOUSE_VET
Insert into IN_HOUSE_VET (VET_ID,SALARY) values (1,35000);
Insert into IN_HOUSE_VET (VET_ID,SALARY) values (2,30000);
Insert into IN_HOUSE_VET (VET_ID,SALARY) values (3,29000);

Class Creation:


VET Class
@Entity
@Table(name = "VET")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "VET_TYPE")
@DiscriminatorValue("VET")
public class Vet implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@Basic(optional = false)
@Column(name = "VET_ID")
private Integer vetId;
@Column(name = "NAME")
private String name;
@Column(name = "QUALIFICATION")
private String qualification;
//generate getters, setters, toString(), hashCode(),equals()
}

EXTERNAT_VET Class
@Entity
@Table(name = "EXTERNAT_VET")
@DiscriminatorValue("EXT_VIT")
public class ExternatVet extends Vet{

@Column(name = "COUNTRY")
private String country;
@Column(name = "VISITING_FEES")
private Integer visitingFees;
//generate getters, setters, toString(), hashCode(),equals()
}

IN_HOUSE_VET Class
@Entity
@Table(name = "IN_HOUSE_VET")
@DiscriminatorValue("IN_VET")
public class InHouseVet extends Vet{

@Column(name = "SALARY")
private Integer salary;
//generate getters, setters, toString(), hashCode(),equals()
}

JUnit Test Case:

public class InheritanceJUnit {

static EntityManagerFactory emf;
static EntityManager em;
static EntityTransaction trx;

@BeforeClass
public static void initEntityManager() throws Exception {
emf = Persistence.createEntityManagerFactory("JavaApplicationJPAPU");
em = emf.createEntityManager();
trx = em.getTransaction();
}

@AfterClass
public static void closeEntityManager() throws Exception {
em.close();
emf.close();
}

@Before
public void initTransaction() throws Exception {
trx.begin();
}

@After
public void endTransaction() throws Exception {
if (!trx.getRollbackOnly()) {
trx.commit();
}
}

@Test
@Ignore
public void testJoinedStrategyInsert() {

InHouseVet inVet = new InHouseVet();
inVet.setName("Invet name 10");
inVet.setQualification("invet Qualification 10");
inVet.setSalary(1010);
inVet.setVetId(10);
em.persist(inVet);
System.out.println("InHouseVet inserted");

ExternatVet extVet = new ExternatVet();
extVet.setName("extVet name 11");
extVet.setQualification("extVet Qualification 11");
extVet.setCountry("xy");
extVet.setVisitingFees(1111);
extVet.setVetId(11);
em.persist(extVet);
System.out.println("ExternatVet inserted");
}

@Test
@Ignore
public void testJoinedStrategySelect() {

Vet vet = em.find(Vet.class, 10);
assertNotNull(vet);

if (vet instanceof ExternatVet) {
ExternatVet externatVet = (ExternatVet) vet;
System.out.println(externatVet);
} else if (vet instanceof InHouseVet) {
InHouseVet inHouseVet = (InHouseVet) vet;
System.out.println(inHouseVet);
} else {
System.out.println("ERROR in Type");
}

Vet vet2 = em.find(Vet.class, 11);
assertNotNull(vet2);

if (vet2 instanceof ExternatVet) {
ExternatVet externatVet = (ExternatVet) vet2;
System.out.println(externatVet);
} else if (vet2 instanceof InHouseVet) {
InHouseVet inHouseVet = (InHouseVet) vet2;
System.out.println(inHouseVet);
} else {
System.out.println("ERROR in Type");
}

Vet vet = em.find(Vet.class, 6);
assertNotNull(vet);

if (vet instanceof ExternatVet) {
ExternatVet externatVet = (ExternatVet) vet;
System.out.println(externatVet);
} else if (vet instanceof InHouseVet) {
InHouseVet inHouseVet = (InHouseVet) vet;
System.out.println(inHouseVet);
} else if (vet instanceof Vet) {
System.out.println(vet);
} else {
System.out.println("ERROR in Type");
}
}

@Test
@Ignore
public void testJoinedStrategyUpdate() {

Vet vet = em.find(Vet.class, 10);
assertNotNull(vet);

if (vet instanceof ExternatVet) {
ExternatVet externatVet = (ExternatVet) vet;
externatVet.setName("extVet Qualification 11 updated");
externatVet.setVisitingFees(101010);
em.merge(externatVet);
System.out.println(externatVet);
} else if (vet instanceof InHouseVet) {
InHouseVet inHouseVet = (InHouseVet) vet;
inHouseVet.setName("Invet name 10 updated");
inHouseVet.setSalary(1010);
em.merge(inHouseVet);
System.out.println(inHouseVet);
} else {
System.out.println("ERROR in Type");
}

Vet vet2 = em.find(Vet.class, 11);
assertNotNull(vet2);

if (vet2 instanceof ExternatVet) {
ExternatVet externatVet = (ExternatVet) vet2;
externatVet.setName("extVet Qualification 11 updated");
externatVet.setVisitingFees(111111);
em.merge(externatVet);
System.out.println(externatVet);
} else if (vet2 instanceof InHouseVet) {
InHouseVet inHouseVet = (InHouseVet) vet2;
inHouseVet.setName("Invet name 11 updated");
inHouseVet.setSalary(1111);
em.merge(inHouseVet);
System.out.println(inHouseVet);
} else {
System.out.println("ERROR in Type");
}
}

@Test
@Ignore
public void testJoinedStrategyDelete() {

Vet vet = em.find(Vet.class, 10);
assertNotNull(vet);
em.remove(vet);
System.out.println("InHouseVet 10 : deleteds");

Vet vet2 = em.find(Vet.class, 11);
assertNotNull(vet2);

if (vet2 instanceof ExternatVet) {
ExternatVet externatVet = (ExternatVet) vet2;
em.remove(externatVet);
System.out.println("ExternatVet 11 : deleted");
} else if (vet2 instanceof InHouseVet) {
InHouseVet inHouseVet = (InHouseVet) vet2;
em.remove(inHouseVet);
System.out.println("InHouseVet 11 : deleteds");
} else {
System.out.println("ERROR in Type");
}
}

}