Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Entities can exhibit inheritance relationship among themselves. The entities involved in inheritance relationship can be persisted/updated/retrieved independently. There are several ways of realizing inheritance relationship among entities. There are as follows.

  • Single database table per class hierarchy
  • Separate database table per subclass
  • Single database table per concrete entity class

Single database table per class hierarchy

...

The persistence schema uses AccountDB derby database. It declares the entities in the persistence unit as well. The following procedure explains how to deploy/run the sample.*

  • Create an EAR application that contains an EJB application packaging all entity classes, ejb classes and META-INF/persistence.xml

...

  • Create META-INF/ejb-jar.xml. Since we have used annotations, we do not have to provide any declarations in it.

...

  • Create a WEB application in the EAR and add the above servlet.

...

  • Create a derby database by name AccountDB using admin console.

...

  • Create a table by name ACCOUNT as following.
    Code Block
    SQL
    SQL
    borderStylesolid
    titleACCOUNT table
    
    create table ACCOUNT(ACCOUNTNO integer, 
                 ACCOUNTTYPE varchar(50), 
                 NAME varchar(50), 
                 ADDRESS varchar(225),
                 BRANCHCODE integer, 
                 INTERESTRATE decimal(15,2), 
                 MINBALANCE decimal(15,2), 
                 BALANCE decimal(15,2), 
                 CURRENTACCOUNTRULES varchar(225), 
                 SAVINGSACCOUNTRULES varchar(225))
    
    The contents of ACCOUNT table in the AccountDB database are as follows.
    No Format
    borderStylesolid
    titleACCOUNT table
    
    ACCOUNTNO ACCOUNTTYPE NAME ADDRESS BRANCHCODE INTERESTRATE MINBALANCE BALANCE CURRENTACCOUNTRULES SAVINGSACCOUNTRULES 
    1 CURRENTACCOUNT Joe Joe's address 10 20.00 200.00 5000.00 Current Account!!  
    2 SAVINGSACCOUNT Joe Joe's address 12 234.00 4534.00 13323.00  Savings Account!! 
    3 CURRENTACCOUNT John John's address 10 20.00 200.00 5000.00 Current Account!!  
    4 SAVINGSACCOUNT John John's address 12 234.00 4534.00 13323.00  Savings Account!!
    
    Note that JPA has inserted the value CURRENTACCOUNT in the column ACCOUNTTYPE for CurrentAccount entities and inserted the value {SAVINGSACCOUNT}} for SavingsAccount entites.