Inheritance Mapping

Logging by Log4j using xml file:

Logging empowers the software engineer to compose the log points of interest into a document for all time. Log4j and Logback structures can be utilized as a part of sleep system to help logging.

  • By log4j.xml file (or)
  • By file

<?xml version=”1.0″ encoding=”UTF-8″?>

<!DOCTYPE log4j:configuration SYSTEM “log4j.dtd”>

<log4j:configuration xmlns:log4j=””


<appender name=”CONSOLE” class=”org.apache.log4j.ConsoleAppender”>

<layout class=”org.apache.log4j.PatternLayout”>

<param name=”ConversionPattern” value=”[%d{dd/MM/yy hh:mm:ss:sss z}] %5p %c{2}: %m%n” />



<appender name=”ASYNC” class=”org.apache.log4j.AsyncAppender”>

<appender-ref ref=”CONSOLE” />

<appender-ref ref=”FILE” />


<appender name=”FILE” class=”org.apache.log4j.RollingFileAppender”>

<param name=”File” value=“C:/javaspotlog.log” />

<param name=”MaxBackupIndex” value=”100″ />

<layout class=”org.apache.log4j.PatternLayout”>

<param name=”ConversionPattern” value=”[%d{dd/MM/yy hh:mm:ss:sss z}] %5p %c{2}: %m%n” />

JAVA Tutorial Video



<category name=”org.hibernate”>

<priority value=”DEBUG” />


<category name=”java.sql”>

<priority value=”debug” />



<priority value=”INFO” />

<appender-ref ref=”FILE” />



Logging by Log4j using properties file:

Log4j and Logback frameworks are used to support logging in hibernate, there are two ways to perform logging using log4j.

  1. By log4j.xml file
  2. By file

# Direct log messages to a log file






log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L – %m%n

# Direct log messages to stdout




log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L – %m%n

# Root logger option

log4j.rootLogger=INFO, file, stdout

# Log everything. Good for troubleshooting

# Log all JDBC parameters

Inheritance Mapping 

Table Per Hierarchy

  • Table Per Concrete class
  • Table Per Subclass

Hibernate Table Per Hierarchy using xml file:

We can delineate legacy order classes with the table of the database. There are three legacy mapping techniques characterized in the rest.


Hierarchy using Annotation

Hierarchy using Annotation

In the past page, we have mapped the legacy progressive system with one table just utilizing xml document. Here, we will play out this undertaking utilizing explanation.

You have to utilize

@Inheritance(strategy=InheritanceType.SINGLE_TABLE), @DiscriminatorColumn and @DiscriminatorValue explanations for mapping table per progression technique.

If there should arise an occurrence of table for each pecking order, just a single table is required to delineate legacy chain of command. Here, an additional segment (otherwise called discriminator segment) is made in the table to recognize the class.

 Hibernate Table Per Hierarchy using Annotation

  • Create the persistent classes
  • Create the configuration file
  • Create the class to store the fetch the data

1) Create the Persistent classes


package com.javaspot.mypackage;

import javax.persistence.*;


@Table(name = “employee101″)




public class Employee {



@Column(name = “id”)

private int id;

@Column(name = “name”)

private String name;

//setters and getters



package com.javaspot.mypackage;

import javax.persistence.*;



public class Regular_Employee extends Employee{


private float salary;


private int bonus;

//setters and getters



package com.javaspot.mypackage;

import javax.persistence.Column;

import javax.persistence.DiscriminatorValue;

import javax.persistence.Entity;



public class Contract_Employee extends Employee{


private float pay_per_hour;


private String contract_duration;

//setters and getters


2) Add the persistent classes in configuration file

<mapping class=”com.javaspot.mypackage.Employee”/>

<mapping class=”com.javaspot.mypackage.Contract_Employee”/>

<mapping class=”com.javaspot.mypackage.Regular_Employee”/>


<table >

<tr><td>Now the configuration file will look like this:



<span id=”filename”>File: hibernate.cfg.xml</span>

<div class=”codeblock”><pre name=”code” class=”java” >

<?xml version=’1.0′ encoding=’UTF-8′?>

<!DOCTYPE hibernate-configuration PUBLIC

“-//Hibernate/Hibernate Configuration DTD 3.0//EN”


<!– Generated by MyEclipse Hibernate Tools.                   –>



<property name=””>update</property>

<property name=”dialect”>org.hibernate.dialect.Oracle9Dialect</property>

<property name=”connection.url”>jdbc:oracle:thin:@localhost:1521:xe</property>

<property name=”connection.username”>system</property>

<property name=”connection.password”>oracle</property>

<property name=”connection.driver_class”>oracle.jdbc.driver.OracleDriver</propert>

<mapping class=”com.javaspot.mypackage.Employee”/>

<mapping class=”com.javaspot.mypackage.Contract_Employee”/>

<mapping class=”com.javaspot.mypackage.Regular_Employee”/>



3) Create the class that stores the persistent object


package com.javaspot.mypackage;

import org.hibernate.*;

import org.hibernate.cfg.*;

public class StoreData {

public static void main(String[] args) {

AnnotationConfiguration cfg=new AnnotationConfiguration();

Session session=cfg.configure(“hibernate.cfg.xml”).buildSessionFactory().openSession();      Transaction t=session.beginTransaction();

Employee e1=new Employee();


Regular_Employee e2=new Regular_Employee();

e2.setName(“Vivek Kumar”);



Contract_Employee e3=new Contract_Employee();

e3.setName(“Arjun Kumar”);


e3.setContract_duration(“15 hours”);









 Table Per Concrete class using Annotation:

If there should be an occurrence of Table Per Concrete class, tables are made per class. So there are no nullable esteems in the table. Weakness of this approach is that copy sections are made in the subclass tables.

Here, we have to utilize @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) comment in the parent class and @AttributeOverrides explanation in the subclasses.

@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) determines that we are utilizing table per solid class methodology. It ought to be determined in the parent class as it were.

@AttributeOverrides characterizes that parent class characteristics will be overriden in this class. In table structure, parent class table sections will be included the subclass table.

Table Per Subclass;

If there should arise an occurrence of Table Per Subclass, subclass mapped tables are identified with parent class mapped table by essential key and remote key relationship.

The <joined-subclass> component of class is utilized to delineate youngster class with parent utilizing the essential key and outside key connection.

In this case, we will utilize property to create the table consequently. So we don’t should be stressed over making tables in the database.

Table Per Subclass using Annotation:

As we have determined before, if there should arise an occurrence of table for every subclass procedure, tables are made according to diligent classes however they are reated utilizing essential and remote key. So there won’t be copy sections in the connection.

We have to indicate @Inheritance(strategy=InheritanceType.JOINED) in the parent class and @PrimaryKeyJoinColumn comment in the subclasses.


to our newsletter

Drop Us A Query

Trending Courses
  • Pega testing training
    PEGA Testing Training
  • Today application testing is the deciding factor to launch the application into the market. And people do not launch the application unless it goes true.

  • blockchain course
    Blockchain Online Course
  • Today many people were enthusiastic, to know the exact details of things happening around him. This can get the proper knowledge on Blockchain.

  • ethical hacking course
    Ethical Hacking Certification Course
  • Zeal to learn ethical hacking is common among college students and IT professionals. Because everybody wants to secure their system from cyber attacks.

  • python training
    Python Online Training
  • Python is a dynamic interrupted language which is used in wide varieties of applications. It is very interactive object oriented and high-level programming language.

  • Tableau Training
    Tableau Training
  • Tableau is a Software company that caters interactive data visualization products that provide Business Intelligence services. The company’s Head Quarters is in Seattle, USA.

  • what is pega
    PEGA Online Training
  • Pega Systems Inc. is a Cambridge, Massachusetts based Software Company. It is known for developing software for Customer Relationship Management (CRM) and Business process Management (BPM).

100% Secure Payments. All major credit & debit cards accepted.