Home Hibernate Hibernate4 Hibernate Logging using Log4j
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Hibernate Logging using Log4j

Advertisement
This section contains detail description of how you can use Log4j for logging configuration.

Hibernate Logging using Log4j

This section contains detail description of how you can use Log4j for logging configuration.

During development or after release, sometimes some unexpected error occurred with the application. To trace the error, logging is very helpful. Log4j is the tool which helps in displaying logs or keeping it's track(for example in a log file). Using Log4j logging can be enable at run time without modifying the application code.

In the below application, we included log4j-1.2.14.jar  in the lib directory to implement logging using Log4j. Log4j is reliable, faster and extensible. It is easy to understand and easy to implement.

Log4j has three main components :

  • Loggers        Loggers is used to log messages.     

  • Appenders  Appenders is used to determine the output destination like console or a file.

  • Layouts       Layouts decides the format log messages should be logged.

For details about the above components please click here.

The project structure is given below :

CODE

hibernate.cfg.xml

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://192.168.10.13:3306/ankdb</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.current_session_context_class">thread</property>

<mapping class="net.roseindia.Worker" />

</session-factory>
</hibernate-configuration>

HandlingWorker.java

package net.roseindia;

import java.util.List;
import java.util.Iterator; 

import org.hibernate.HibernateException; 
import org.hibernate.Session; 
import org.hibernate.Transaction;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;


public class HandlingWorker {
private static SessionFactory factory;
private static ServiceRegistry serviceRegistry;

public static void main(String[] args) {
try{
Configuration configuration = new Configuration();
configuration.configure();
serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry(); 
factory = configuration.buildSessionFactory(serviceRegistry);
}catch (Throwable ex) { 
System.err.println("Failed to create sessionFactory object." + ex);
throw new ExceptionInInitializerError(ex); 
}
HandlingWorker handle = new HandlingWorker();

/* Add few worker records in database */
Integer worker1 = handle.addWorker("Kumar", "Dhawan", 1000);
Integer worker2 = handle.addWorker("Sriprakash", "Marathe", 5000);
Integer worker3 = handle.addWorker("Rudra", "Shah", 10000);

/* List down all the workers */
handle.listWorkers();

/* Update worker's records */
handle.updateWorker(worker1, 5000);
handle.updateWorker(worker3, 15000);

/* Delete an worker from the database */
handle.deleteWorker(worker2);

/* List down new list of the workers */
handle.listWorkers();
}
/* Method to CREATE an worker in the database */
public Integer addWorker(String fname, String lname, int salary){
Session session = factory.openSession();
Transaction tx = null;
Integer workerID = null;
try{
tx = session.beginTransaction();
Worker worker = new Worker(fname, lname, salary);
workerID = (Integer) session.save(worker); 
tx.commit();
}catch (HibernateException e) {
if (tx!=null) tx.rollback();
e.printStackTrace(); 
}finally {
session.close(); 
}
return workerID;
}
/* Method to READ all the employees */
public void listWorkers( ){
Session session = factory.openSession();
Transaction tx = null;
try{
tx = session.beginTransaction();
List employees = session.createQuery("FROM Worker").list(); 
for (Iterator iterator = 
employees.iterator(); iterator.hasNext();){
Worker worker = (Worker) iterator.next(); 
System.out.print("First Name: " + worker.getFirstName()); 
System.out.print(" Last Name: " + worker.getLastName()); 
System.out.println(" Salary: " + worker.getSalary()); 
}
tx.commit();
}catch (HibernateException e) {
if (tx!=null) tx.rollback();
e.printStackTrace(); 
}finally {
session.close(); 
}
}
/* Method to UPDATE salary for an worker */
public void updateWorker(Integer WorkerID, int salary ){
Session session = factory.openSession();
Transaction tx = null;
try{
tx = session.beginTransaction();
Worker worker = 
(Worker)session.get(Worker.class, WorkerID); 
worker.setSalary( salary );
session.update(worker); 
tx.commit();
}catch (HibernateException e) {
if (tx!=null) tx.rollback();
e.printStackTrace(); 
}finally {
session.close(); 
}
}
/* Method to DELETE an worker from the records */
public void deleteWorker(Integer WorkerID){
Session session = factory.openSession();
Transaction tx = null;
try{
tx = session.beginTransaction();
Worker worker = 
(Worker)session.get(Worker.class, WorkerID); 
session.delete(worker); 
tx.commit();
}catch (HibernateException e) {
if (tx!=null) tx.rollback();
e.printStackTrace(); 
}finally {
session.close(); 
}
}
}

Worker.java

package net.roseindia;

import javax.persistence.*;

@Entity
@Table(name = "Worker")
public class Worker {
@Id
@GeneratedValue
@Column(name = "id")
private int id;

@Column(name = "first_name")
private String firstName;

@Column(name = "last_name")
private String lastName;

@Column(name = "salary")
private int salary;

public Worker() {
}

public Worker(String fname, String lname, int salary) {
this.firstName = fname;
this.lastName = lname;
this.salary = salary;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}


public String getFirstName() {
return firstName;
}

public void setFirstName(String first_name) {
this.firstName = first_name;
}

public String getLastName() {
return lastName;
}

public void setLastName(String last_name) {
this.lastName = last_name;
}

public int getSalary() {
return salary;
}

public void setSalary(int salary) {
this.salary = salary;
}
}

log4j.properties

# Save log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=C:\\PROJECTLOG.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}:%L - %m%n

# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
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
log4j.logger.org.hibernate=INFO

# Log all JDBC parameters
log4j.logger.org.hibernate.type=ALL

The above configuration will  print the logs on console and also save the logs on the file saved in C: drive (C:\\PROJECTLOG.log). To download this log file click here.

OUTPUT

13:13:22,828 DEBUG BasicTypeRegistry:143 - Adding type registration boolean -> org.hibernate.type.BooleanType@67ac19
13:13:22,828 DEBUG BasicTypeRegistry:143 - Adding type registration boolean -> org.hibernate.type.BooleanType@67ac19
13:13:22,828 DEBUG BasicTypeRegistry:143 - Adding type registration java.lang.Boolean -> org.hibernate.type.BooleanType@67ac19
13:13:22,828 DEBUG BasicTypeRegistry:143 - Adding type registration numeric_boolean -> org.hibernate.type.NumericBooleanType@1813fac
13:13:22,828 DEBUG BasicTypeRegistry:143 - Adding type registration true_false -> org.hibernate.type.TrueFalseType@1c672d0
13:13:22,828 DEBUG BasicTypeRegistry:143 - Adding type registration yes_no -> org.hibernate.type.YesNoType@bfbdb0
13:13:22,828 DEBUG BasicTypeRegistry:143 - Adding type registration byte -> org.hibernate.type.ByteType@253498
13:13:22,828 DEBUG BasicTypeRegistry:143 - Adding type registration byte -> org.hibernate.type.ByteType@253498
13:13:22,828 DEBUG BasicTypeRegistry:143 - Adding type registration java.lang.Byte -> org.hibernate.type.ByteType@253498
13:13:22,828 DEBUG BasicTypeRegistry:143 - Adding type registration character -> org.hibernate.type.CharacterType@1bac748
13:13:22,828 DEBUG BasicTypeRegistry:143 - Adding type registration char -> org.hibernate.type.CharacterType@1bac748
13:13:22,828 DEBUG BasicTypeRegistry:143 - Adding type registration java.lang.Character -> org.hibernate.type.CharacterType@1bac748
13:13:22,828 DEBUG BasicTypeRegistry:143 - Adding type registration short -> org.hibernate.type.ShortType@4b222f
13:13:22,828 DEBUG BasicTypeRegistry:143 - Adding type registration short -> org.hibernate.type.ShortType@4b222f
13:13:22,828 DEBUG BasicTypeRegistry:143 - Adding type registration java.lang.Short -> org.hibernate.type.ShortType@4b222f
13:13:22,843 DEBUG BasicTypeRegistry:143 - Adding type registration integer -> org.hibernate.type.IntegerType@7a78d3
13:13:22,843 DEBUG BasicTypeRegistry:143 - Adding type registration int -> org.hibernate.type.IntegerType@7a78d3
13:13:22,843 DEBUG BasicTypeRegistry:143 - Adding type registration java.lang.Integer -> org.hibernate.type.IntegerType@7a78d3
13:13:22,843 DEBUG BasicTypeRegistry:143 - Adding type registration long -> org.hibernate.type.LongType@1855af5
13:13:22,843 DEBUG BasicTypeRegistry:143 - Adding type registration long -> org.hibernate.type.LongType@1855af5
13:13:22,843 DEBUG BasicTypeRegistry:143 - Adding type registration java.lang.Long -> org.hibernate.type.LongType@1855af5
13:13:22,843 DEBUG BasicTypeRegistry:143 - Adding type registration float -> org.hibernate.type.FloatType@9fbe93
13:13:22,843 DEBUG BasicTypeRegistry:143 - Adding type registration float -> org.hibernate.type.FloatType@9fbe93
13:13:22,843 DEBUG BasicTypeRegistry:143 - Adding type registration java.lang.Float -> org.hibernate.type.FloatType@9fbe93
13:13:22,843 DEBUG BasicTypeRegistry:143 - Adding type registration double -> org.hibernate.type.DoubleType@1a5ab41
13:13:22,843 DEBUG BasicTypeRegistry:143 - Adding type registration double -> org.hibernate.type.DoubleType@1a5ab41
13:13:22,843 DEBUG BasicTypeRegistry:143 - Adding type registration java.lang.Double -> org.hibernate.type.DoubleType@1a5ab41
13:13:22,843 DEBUG BasicTypeRegistry:143 - Adding type registration big_decimal -> org.hibernate.type.BigDecimalType@131f71a
13:13:22,843 DEBUG BasicTypeRegistry:143 - Adding type registration java.math.BigDecimal -> org.hibernate.type.BigDecimalType@131f71a
13:13:22,843 DEBUG BasicTypeRegistry:143 - Adding type registration big_integer -> org.hibernate.type.BigIntegerType@7259da
13:13:22,843 DEBUG BasicTypeRegistry:143 - Adding type registration java.math.BigInteger -> org.hibernate.type.BigIntegerType@7259da
13:13:22,843 DEBUG BasicTypeRegistry:143 - Adding type registration string -> org.hibernate.type.StringType@119c082
13:13:22,843 DEBUG BasicTypeRegistry:143 - Adding type registration java.lang.String -> org.hibernate.type.StringType@119c082
13:13:22,843 DEBUG BasicTypeRegistry:143 - Adding type registration url -> org.hibernate.type.UrlType@194df86
13:13:22,843 DEBUG BasicTypeRegistry:143 - Adding type registration java.net.URL -> org.hibernate.type.UrlType@194df86
13:13:22,843 DEBUG BasicTypeRegistry:143 - Adding type registration date -> org.hibernate.type.DateType@107077e
13:13:22,843 DEBUG BasicTypeRegistry:143 - Adding type registration java.sql.Date -> org.hibernate.type.DateType@107077e
13:13:22,843 DEBUG BasicTypeRegistry:143 - Adding type registration time -> org.hibernate.type.TimeType@14f8dab
13:13:22,843 DEBUG BasicTypeRegistry:143 - Adding type registration java.sql.Time -> org.hibernate.type.TimeType@14f8dab
13:13:22,859 DEBUG BasicTypeRegistry:143 - Adding type registration timestamp -> org.hibernate.type.TimestampType@17943a4
13:13:22,859 DEBUG BasicTypeRegistry:143 - Adding type registration java.sql.Timestamp -> org.hibernate.type.TimestampType@17943a4
13:13:22,859 DEBUG BasicTypeRegistry:143 - Adding type registration java.util.Date -> org.hibernate.type.TimestampType@17943a4
13:13:22,859 DEBUG BasicTypeRegistry:143 - Adding type registration dbtimestamp -> org.hibernate.type.DbTimestampType@14fe5c
13:13:22,859 DEBUG BasicTypeRegistry:143 - Adding type registration calendar -> org.hibernate.type.CalendarType@2bbd86
13:13:22,859 DEBUG BasicTypeRegistry:143 - Adding type registration java.util.Calendar -> org.hibernate.type.CalendarType@2bbd86
13:13:22,859 DEBUG BasicTypeRegistry:143 - Adding type registration java.util.GregorianCalendar -> org.hibernate.type.CalendarType@2bbd86
13:13:22,859 DEBUG BasicTypeRegistry:143 - Adding type registration calendar_date -> org.hibernate.type.CalendarDateType@1f12c4e
13:13:22,859 DEBUG BasicTypeRegistry:143 - Adding type registration locale -> org.hibernate.type.LocaleType@df6ccd
13:13:22,859 DEBUG BasicTypeRegistry:143 - Adding type registration java.util.Locale -> org.hibernate.type.LocaleType@df6ccd
13:13:22,859 DEBUG BasicTypeRegistry:143 - Adding type registration currency -> org.hibernate.type.CurrencyType@1ea2dfe
13:13:22,859 DEBUG BasicTypeRegistry:143 - Adding type registration java.util.Currency -> org.hibernate.type.CurrencyType@1ea2dfe
13:13:22,859 DEBUG BasicTypeRegistry:143 - Adding type registration timezone -> org.hibernate.type.TimeZoneType@f4a24a
13:13:22,859 DEBUG BasicTypeRegistry:143 - Adding type registration java.util.TimeZone -> org.hibernate.type.TimeZoneType@f4a24a
13:13:22,859 DEBUG BasicTypeRegistry:143 - Adding type registration class -> org.hibernate.type.ClassType@1cde100
13:13:22,859 DEBUG BasicTypeRegistry:143 - Adding type registration java.lang.Class -> org.hibernate.type.ClassType@1cde100
13:13:22,859 DEBUG BasicTypeRegistry:143 - Adding type registration uuid-binary -> org.hibernate.type.UUIDBinaryType@ad3ba4
13:13:22,859 DEBUG BasicTypeRegistry:143 - Adding type registration java.util.UUID -> org.hibernate.type.UUIDBinaryType@ad3ba4
13:13:22,859 DEBUG BasicTypeRegistry:143 - Adding type registration uuid-char -> org.hibernate.type.UUIDCharType@182f0db
13:13:22,859 DEBUG BasicTypeRegistry:143 - Adding type registration pg-uuid -> org.hibernate.type.PostgresUUIDType@1c78e57
13:13:22,859 DEBUG BasicTypeRegistry:143 - Adding type registration binary -> org.hibernate.type.BinaryType@15ff48b
13:13:22,859 DEBUG BasicTypeRegistry:143 - Adding type registration byte[] -> org.hibernate.type.BinaryType@15ff48b
13:13:22,859 DEBUG BasicTypeRegistry:143 - Adding type registration [B -> org.hibernate.type.BinaryType@15ff48b
13:13:22,859 DEBUG BasicTypeRegistry:143 - Adding type registration wrapper-binary -> org.hibernate.type.WrapperBinaryType@1004901
13:13:22,859 DEBUG BasicTypeRegistry:143 - Adding type registration Byte[] -> org.hibernate.type.WrapperBinaryType@1004901
13:13:22,859 DEBUG BasicTypeRegistry:143 - Adding type registration [Ljava.lang.Byte; -> org.hibernate.type.WrapperBinaryType@1004901
13:13:22,859 DEBUG BasicTypeRegistry:143 - Adding type registration image -> org.hibernate.type.ImageType@b8df17
13:13:22,875 DEBUG BasicTypeRegistry:143 - Adding type registration characters -> org.hibernate.type.CharArrayType@9664a1
13:13:22,875 DEBUG BasicTypeRegistry:143 - Adding type registration char[] -> org.hibernate.type.CharArrayType@9664a1
13:13:22,875 DEBUG BasicTypeRegistry:143 - Adding type registration [C -> org.hibernate.type.CharArrayType@9664a1
13:13:22,875 DEBUG BasicTypeRegistry:143 - Adding type registration wrapper-characters -> org.hibernate.type.CharacterArrayType@cf2c80
13:13:22,875 DEBUG BasicTypeRegistry:143 - Adding type registration [Ljava.lang.Character; -> org.hibernate.type.CharacterArrayType@cf2c80
13:13:22,875 DEBUG BasicTypeRegistry:143 - Adding type registration Character[] -> org.hibernate.type.CharacterArrayType@cf2c80
13:13:22,875 DEBUG BasicTypeRegistry:143 - Adding type registration text -> org.hibernate.type.TextType@19f953d
13:13:22,875 DEBUG BasicTypeRegistry:143 - Adding type registration blob -> org.hibernate.type.BlobType@1fc4bec
13:13:22,875 DEBUG BasicTypeRegistry:143 - Adding type registration java.sql.Blob -> org.hibernate.type.BlobType@1fc4bec
13:13:22,875 DEBUG BasicTypeRegistry:143 - Adding type registration materialized_blob -> org.hibernate.type.MaterializedBlobType@1bab50a
13:13:22,875 DEBUG BasicTypeRegistry:143 - Adding type registration clob -> org.hibernate.type.ClobType@7c6768
13:13:22,875 DEBUG BasicTypeRegistry:143 - Adding type registration java.sql.Clob -> org.hibernate.type.ClobType@7c6768
13:13:22,875 DEBUG BasicTypeRegistry:143 - Adding type registration materialized_clob -> org.hibernate.type.MaterializedClobType@5483cd
13:13:22,875 DEBUG BasicTypeRegistry:143 - Adding type registration serializable -> org.hibernate.type.SerializableType@1f1fba0
13:13:22,875 DEBUG BasicTypeRegistry:143 - Adding type registration object -> org.hibernate.type.ObjectType@c2ea3f
13:13:22,875 DEBUG BasicTypeRegistry:143 - Adding type registration java.lang.Object -> org.hibernate.type.ObjectType@c2ea3f
13:13:22,875 DEBUG BasicTypeRegistry:143 - Adding type registration imm_date -> org.hibernate.type.AdaptedImmutableType@1034bb5
13:13:22,875 DEBUG BasicTypeRegistry:143 - Adding type registration imm_time -> org.hibernate.type.AdaptedImmutableType@15f5897
13:13:22,875 DEBUG BasicTypeRegistry:143 - Adding type registration imm_timestamp -> org.hibernate.type.AdaptedImmutableType@b162d5
13:13:22,875 DEBUG BasicTypeRegistry:143 - Adding type registration imm_dbtimestamp -> org.hibernate.type.AdaptedImmutableType@1cfb549
13:13:22,890 DEBUG BasicTypeRegistry:143 - Adding type registration imm_calendar -> org.hibernate.type.AdaptedImmutableType@f9f9d8
13:13:22,890 DEBUG BasicTypeRegistry:143 - Adding type registration imm_calendar_date -> org.hibernate.type.AdaptedImmutableType@1820dda
13:13:22,890 DEBUG BasicTypeRegistry:143 - Adding type registration imm_binary -> org.hibernate.type.AdaptedImmutableType@15b7986
13:13:22,890 DEBUG BasicTypeRegistry:143 - Adding type registration imm_serializable -> org.hibernate.type.AdaptedImmutableType@87816d
13:13:22,906 INFO Version:37 - HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
13:13:22,906 INFO Version:41 - HHH000412: Hibernate Core {4.0.0.Final}
13:13:22,906 INFO Environment:239 - HHH000206: hibernate.properties not found
13:13:22,906 INFO Environment:342 - HHH000021: Bytecode provider name : javassist
13:13:22,921 INFO Configuration:1920 - HHH000043: Configuring from resource: /hibernate.cfg.xml
13:13:22,921 INFO Configuration:1939 - HHH000040: Configuration resource: /hibernate.cfg.xml
13:13:22,968 WARN DTDEntityResolver:74 - HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
13:13:22,984 INFO Configuration:2061 - HHH000041: Configured SessionFactory: null
13:13:23,109 INFO DriverManagerConnectionProviderImpl:90 - HHH000402: Using Hibernate built-in connection pool (not for production use!)
13:13:23,109 INFO DriverManagerConnectionProviderImpl:110 - HHH000115: Hibernate connection pool size: 10
13:13:23,109 INFO DriverManagerConnectionProviderImpl:113 - HHH000006: Autocommit mode: false
13:13:23,109 INFO DriverManagerConnectionProviderImpl:127 - HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://192.168.10.13:3306/ankdb]
13:13:23,109 INFO DriverManagerConnectionProviderImpl:132 - HHH000046: Connection properties: {user=root, password=****}
13:13:23,281 INFO Dialect:120 - HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
13:13:23,296 INFO LobCreatorBuilder:94 - HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
13:13:23,296 INFO TransactionFactoryInitiator:68 - HHH000399: Using default transaction strategy (direct JDBC transactions)
13:13:23,296 INFO ASTQueryTranslatorFactory:48 - HHH000397: Using ASTQueryTranslatorFactory
13:13:23,312 TRACE TypeFactory:72 - Scoping types to session factory org.hibernate.internal.SessionFactoryImpl@1af33d6
Hibernate: insert into Worker (first_name, last_name, salary) values (?, ?, ?)
13:13:23,546 TRACE BasicBinder:83 - binding parameter [1] as [VARCHAR] - Kumar
13:13:23,546 TRACE BasicBinder:83 - binding parameter [2] as [VARCHAR] - Dhawan
13:13:23,546 TRACE BasicBinder:83 - binding parameter [3] as [INTEGER] - 1000
Hibernate: insert into Worker (first_name, last_name, salary) values (?, ?, ?)
13:13:23,687 TRACE BasicBinder:83 - binding parameter [1] as [VARCHAR] - Sriprakash
13:13:23,687 TRACE BasicBinder:83 - binding parameter [2] as [VARCHAR] - Marathe
13:13:23,687 TRACE BasicBinder:83 - binding parameter [3] as [INTEGER] - 5000
Hibernate: insert into Worker (first_name, last_name, salary) values (?, ?, ?)
13:13:23,734 TRACE BasicBinder:83 - binding parameter [1] as [VARCHAR] - Rudra
13:13:23,734 TRACE BasicBinder:83 - binding parameter [2] as [VARCHAR] - Shah
13:13:23,734 TRACE BasicBinder:83 - binding parameter [3] as [INTEGER] - 10000
Hibernate: select worker0_.id as id0_, worker0_.first_name as first2_0_, worker0_.last_name as last3_0_, worker0_.salary as salary0_ from Worker worker0_
13:13:23,843 TRACE BasicExtractor:72 - Found [43] as column [id0_]
13:13:23,843 TRACE BasicExtractor:72 - Found [Kumar] as column [first2_0_]
13:13:23,843 TRACE BasicExtractor:72 - Found [Dhawan] as column [last3_0_]
13:13:23,843 TRACE BasicExtractor:72 - Found [1000] as column [salary0_]
13:13:23,843 TRACE BasicExtractor:72 - Found [44] as column [id0_]
13:13:23,843 TRACE BasicExtractor:72 - Found [Sriprakash] as column [first2_0_]
13:13:23,843 TRACE BasicExtractor:72 - Found [Marathe] as column [last3_0_]
13:13:23,843 TRACE BasicExtractor:72 - Found [5000] as column [salary0_]
13:13:23,843 TRACE BasicExtractor:72 - Found [45] as column [id0_]
13:13:23,843 TRACE BasicExtractor:72 - Found [Rudra] as column [first2_0_]
13:13:23,843 TRACE BasicExtractor:72 - Found [Shah] as column [last3_0_]
13:13:23,843 TRACE BasicExtractor:72 - Found [10000] as column [salary0_]
First Name: Kumar Last Name: Dhawan Salary: 1000
First Name: Sriprakash Last Name: Marathe Salary: 5000
First Name: Rudra Last Name: Shah Salary: 10000
Hibernate: select worker0_.id as id0_0_, worker0_.first_name as first2_0_0_, worker0_.last_name as last3_0_0_, worker0_.salary as salary0_0_ from Worker worker0_ where worker0_.id=?
13:13:23,843 TRACE BasicBinder:83 - binding parameter [1] as [INTEGER] - 43
13:13:23,843 TRACE BasicExtractor:72 - Found [Kumar] as column [first2_0_0_]
13:13:23,843 TRACE BasicExtractor:72 - Found [Dhawan] as column [last3_0_0_]
13:13:23,843 TRACE BasicExtractor:72 - Found [1000] as column [salary0_0_]
Hibernate: update Worker set first_name=?, last_name=?, salary=? where id=?
13:13:23,859 TRACE BasicBinder:83 - binding parameter [1] as [VARCHAR] - Kumar
13:13:23,859 TRACE BasicBinder:83 - binding parameter [2] as [VARCHAR] - Dhawan
13:13:23,859 TRACE BasicBinder:83 - binding parameter [3] as [INTEGER] - 5000
13:13:23,859 TRACE BasicBinder:83 - binding parameter [4] as [INTEGER] - 43
Hibernate: select worker0_.id as id0_0_, worker0_.first_name as first2_0_0_, worker0_.last_name as last3_0_0_, worker0_.salary as salary0_0_ from Worker worker0_ where worker0_.id=?
13:13:23,890 TRACE BasicBinder:83 - binding parameter [1] as [INTEGER] - 45
13:13:23,890 TRACE BasicExtractor:72 - Found [Rudra] as column [first2_0_0_]
13:13:23,890 TRACE BasicExtractor:72 - Found [Shah] as column [last3_0_0_]
13:13:23,890 TRACE BasicExtractor:72 - Found [10000] as column [salary0_0_]
Hibernate: update Worker set first_name=?, last_name=?, salary=? where id=?
13:13:23,890 TRACE BasicBinder:83 - binding parameter [1] as [VARCHAR] - Rudra
13:13:23,890 TRACE BasicBinder:83 - binding parameter [2] as [VARCHAR] - Shah
13:13:23,890 TRACE BasicBinder:83 - binding parameter [3] as [INTEGER] - 15000
13:13:23,890 TRACE BasicBinder:83 - binding parameter [4] as [INTEGER] - 45
Hibernate: select worker0_.id as id0_0_, worker0_.first_name as first2_0_0_, worker0_.last_name as last3_0_0_, worker0_.salary as salary0_0_ from Worker worker0_ where worker0_.id=?
13:13:23,937 TRACE BasicBinder:83 - binding parameter [1] as [INTEGER] - 44
13:13:23,937 TRACE BasicExtractor:72 - Found [Sriprakash] as column [first2_0_0_]
13:13:23,937 TRACE BasicExtractor:72 - Found [Marathe] as column [last3_0_0_]
13:13:23,937 TRACE BasicExtractor:72 - Found [5000] as column [salary0_0_]
Hibernate: delete from Worker where id=?
13:13:23,937 TRACE BasicBinder:83 - binding parameter [1] as [INTEGER] - 44
Hibernate: select worker0_.id as id0_, worker0_.first_name as first2_0_, worker0_.last_name as last3_0_, worker0_.salary as salary0_ from Worker worker0_
13:13:23,984 TRACE BasicExtractor:72 - Found [43] as column [id0_]
13:13:23,984 TRACE BasicExtractor:72 - Found [Kumar] as column [first2_0_]
13:13:23,984 TRACE BasicExtractor:72 - Found [Dhawan] as column [last3_0_]
13:13:23,984 TRACE BasicExtractor:72 - Found [5000] as column [salary0_]
13:13:23,984 TRACE BasicExtractor:72 - Found [45] as column [id0_]
13:13:23,984 TRACE BasicExtractor:72 - Found [Rudra] as column [first2_0_]
13:13:23,984 TRACE BasicExtractor:72 - Found [Shah] as column [last3_0_]
13:13:23,984 TRACE BasicExtractor:72 - Found [15000] as column [salary0_]
First Name: Kumar Last Name: Dhawan Salary: 5000
First Name: Rudra Last Name: Shah Salary: 15000

In the worker table, you will get the following :

Download Source Code

Advertisement

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: March 2, 2012

Ask Questions?    Discuss: Hibernate Logging using Log4j  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com