Inheritance Mapping

Click to rate this post!
[Total: 0 Average: 0]
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
  • oracle 12c rac | OnlineITGuru
    Oracle RAC Training
  • Oracle is the large vendor in providing the various storge services to the people across the globe. This vendor provides a different amount of storage services to the people across the globe.

  • salesforce lightning training | OnlineITGuru
    Salesforce Lightning Training
  • Developing an application is not a simple and easy task. There are various parameters that the web developer need to take care while developing an application. One of those parameters that the developer needs to take care of is the code reusability.

  • Selenium with python
    Selenium with Python Training
  • As we know, that Selenium with Python Web Browser Selenium Automation is Gaining Popularity Day by Day. So many Frameworks and Tools Have arisen to get Services to Developers.

  • machine learning with python
    Machine Learning with Python Training
  • Over last few years, Big Data and analysis have come up, with Exponential and modified Direction of Business. That operate Python, emerged with a fast and strong Contender for going with Predictive Analysis.

  • Data science with R
    Data Science With R Training
  • Understanding and using Linear, non-linear regression Models and Classifying techniques for stats analysis. Hypothesis testing sample methods, to get business decisions.

  • data science with python
    Data Science with Python Training
  • Everyone starts Somewhere, first you learn basics of Every Scripting concept. Here you need complete Introduction to Data Science python libraries Concepts.

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

Call Now Button