Posts

Hibernate 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: By log4j.xml file (or) By log4j.properties file Here, we are going to enable logging using log4j through properties file. Create log4j.properties file Now you need to create log4j.properties file. In this example, all the log details will be written in the D:\\logfilename.log file.( location where you want) if you want logs present inside log folder which are created inside the src folder then write  logs/logfilename.log # Direct log messages to a log file log4j.appender.file = org.apache.log4j.RollingFileAppender #log4j.appender.file.File=D:\\javatpointhibernate.log # Define the log folder path log4j.appender.file.File= logs/javatpointhibernate.log log4j.appender.file.MaxFileSize= 1MB log4j.appender.file.MaxBackupIndex= 1 log4j.appender.file.layout = org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern= %d{ABSOLUTE} %5p %c {1}...

Hibernate - Examples

  Create POJO Classes The first step in creating an application is to build the Java POJO class or classes, depending on the application that will be persisted to the database. Let us consider our  Employee  class with  getXXX  and  setXXX  methods to make it JavaBeans compliant class. A POJO (Plain Old Java Object) is a Java object that doesn't extend or implement some specialized classes and interfaces respectively required by the EJB framework. All normal Java objects are POJO. When you design a class to be persisted by Hibernate, it is important to provide JavaBeans compliant code as well as one attribute, which would work as index like  id  attribute in the Employee class. package hbm; public class Employee {    private int id;    private String firstName;     private String lastName;       private int salary;      public Employee() {}    pub...