Nikos Maravitsas

About Nikos Maravitsas

Nikos has graduated from the Department of Informatics and Telecommunications of The National and Kapodistrian University of Athens. Currently, his main interests are system’s security, parallel systems, artificial intelligence, operating systems, system programming, telecommunications, web applications, human – machine interaction and mobile development.

Hibernate Logging Configuration – SLF4J + Log4j and Logback

In this example we are going to see how to configure Logging in Hibernate. SLF4J (Simple Logging Facade for Java) is a very nice logging framwork that Hibernate uses, in order to output your logs using your favorite logging tool ( log4j, JCL, JDK logging, logback) to your preferd location. We are going to use SLF4J along with log4j and Logback.

So these are the tools we are going to use on a Windows 7 platform:

  • JDK 1.7
  • Maven 3.0.5
  • Hibernate 4.2.3.Final
  • MySQL JDBC driver 5.1.9
  • Eclipse 4.3 Kepler

The basis of this tutorials is going to be this Eclipse project: HibernateMySQLExample.zip

Logging with log4j

Remember that the basic structure of our program is this:

project_struvture

1. Download SLF4J and log4j

In order to work with slf4j and log4j, normally you should add some dependencies in your pom.xml. That way, Maven would download the appropriate jars for these libraries. The thing is that Hibernate 4.2.3.Final aytomatically fetches and uses the appropriate versions of core library files of slf4j. You have to be careful with that beacause if you specify your own dependencies for core jars in pom.xml there’s a chance that you will download incompatible versions of slf4j and log4j and then you’ll get warnings like:

log4j:WARN No appenders could be found for logger (org.hibernate.type.BasicTypeRegistry).
log4j:WARN Please initialize the log4j system properly.

or

SLF4J: Class path contains multiple SLF4J bindings.

Basically this means that there are many versions of the framworks in your system and that you should remove the incompatible ones.

Fortunately, the latest version of Hibernates takes care of these and there is no need to specify manually these versions of slf4j-core and. What you should specify is slf4j-log4j12 in order to use log4j along with slf4j library. Here we are going to use the latest version of slf4j-log4j12 which downloads an uses log4j version 1.2.17.

So this is the pom.xml of our project:

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.javacodegeeks</groupId>
	<artifactId>HibernateMySQLExample</artifactId>
	<packaging>jar</packaging>
	<version>1.0-SNAPSHOT</version>
	<name>HibernateMySQLExample</name>
	<url>http://maven.apache.org</url>

	<!-- JBoss repository for Hibernate -->

	<repositories>
		<repository>
			<id>JBoss repository</id>
			<url>http://repository.jboss.org/nexus/content/groups/public/</url>
		</repository>
	</repositories>

	<dependencies>

		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-core</artifactId>
			<version>4.2.3.Final</version>
		</dependency>

		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>5.1.9</version>
		</dependency> 

		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-log4j12</artifactId>
			<version>1.7.5</version>
		</dependency>

	</dependencies>

</project>

2. log4j properties file

In order to configure log4j properly you have to add a log4j.properties file in your class path. So go to the Package Explorer and find /src/main/resources folder:

project_struvture

Right click on the folder -> New -> Other -> General -> File. The create a new file named “log4j.properties“:

new-file

So the new project structure should look like this:

new-project-structure

Open the file and paste the following lines

log4j.properties:

# Direct to file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=F:/nikos7/Desktop/log4jLogs
log4j.appender.file.MaxFileSize=2MB
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 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

# Good for troubleshooting
log4j.logger.org.hibernate=INFO

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

This will gather anything worth for troubelshouting and display the logs in the Standard Output, as well as store them in a log file, F:/nikos7/Desktop/log4jLogs.

The output of the program would be:

17:44:30,772 DEBUG BasicTypeRegistry:148 - Adding type registration boolean -> org.hibernate.type.BooleanType@7e5dfc79
17:44:30,774 DEBUG BasicTypeRegistry:148 - Adding type registration boolean -> org.hibernate.type.BooleanType@7e5dfc79
17:44:30,775 DEBUG BasicTypeRegistry:148 - Adding type registration java.lang.Boolean -> org.hibernate.type.BooleanType@7e5dfc79
17:44:30,776 DEBUG BasicTypeRegistry:148 - Adding type registration numeric_boolean -> org.hibernate.type.NumericBooleanType@57baf36f
17:44:30,777 DEBUG BasicTypeRegistry:148 - Adding type registration true_false -> org.hibernate.type.TrueFalseType@6d2a3e06
17:44:30,778 DEBUG BasicTypeRegistry:148 - Adding type registration yes_no -> org.hibernate.type.YesNoType@694c6171
17:44:30,780 DEBUG BasicTypeRegistry:148 - Adding type registration byte -> org.hibernate.type.ByteType@7d7c214d
17:44:30,780 DEBUG BasicTypeRegistry:148 - Adding type registration byte -> org.hibernate.type.ByteType@7d7c214d
17:44:30,780 DEBUG BasicTypeRegistry:148 - Adding type registration java.lang.Byte -> org.hibernate.type.ByteType@7d7c214d
17:44:30,781 DEBUG BasicTypeRegistry:148 - Adding type registration character -> org.hibernate.type.CharacterType@4045548
17:44:30,781 DEBUG BasicTypeRegistry:148 - Adding type registration char -> org.hibernate.type.CharacterType@4045548
...
17:44:30,854  INFO Version:37 - HCANN000001: Hibernate Commons Annotations {4.0.2.Final}
17:44:30,860  INFO Version:41 - HHH000412: Hibernate Core {4.2.3.Final}
17:44:30,861  INFO Environment:239 - HHH000206: hibernate.properties not found
17:44:30,863  INFO Environment:342 - HHH000021: Bytecode provider name : javassist
17:44:30,879  INFO Configuration:1985 - HHH000043: Configuring from resource: /hibernate.cfg.xml
17:44:30,880  INFO Configuration:2004 - HHH000040: Configuration resource: /hibernate.cfg.xml
17:44:30,913  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!
17:44:30,928  INFO Configuration:728 - HHH000221: Reading mappings from resource: com/javacodegeeks/Student.hbm.xml
17:44:30,944  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!
17:44:30,974  INFO Configuration:2126 - HHH000041: Configured SessionFactory: null
17:44:31,007  INFO DriverManagerConnectionProviderImpl:98 - HHH000402: Using Hibernate built-in connection pool (not for production use!)
17:44:31,011  INFO DriverManagerConnectionProviderImpl:134 - HHH000115: Hibernate connection pool size: 20
17:44:31,011  INFO DriverManagerConnectionProviderImpl:137 - HHH000006: Autocommit mode: false
17:44:31,011  INFO DriverManagerConnectionProviderImpl:151 - HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/tutorials]
17:44:31,011  INFO DriverManagerConnectionProviderImpl:156 - HHH000046: Connection properties: {user=root, password=****}
17:44:31,208  INFO Dialect:130 - HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
17:44:31,216  INFO LobCreatorBuilder:94 - HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
17:44:31,260  INFO TransactionFactoryInitiator:68 - HHH000399: Using default transaction strategy (direct JDBC transactions)
17:44:31,264  INFO ASTQueryTranslatorFactory:48 - HHH000397: Using ASTQueryTranslatorFactory
17:44:31,279 TRACE TypeFactory:71 - Scoping types to session factory org.hibernate.internal.SessionFactoryImpl@4668e679
Hibernate: insert into tutorials.student (STUDENT_NAME, STUDENT_Age) values (?, ?)
17:44:31,502 TRACE BasicBinder:84 - binding parameter [1] as [VARCHAR] - JavaFun
17:44:31,502 TRACE BasicBinder:84 - binding parameter [2] as [VARCHAR] - 19
Great! Student was saved

Please note that Hibernate has a number of logging options. You can find more information in Hibernate Log Categories.

This was an example on how to use SLF4J with log4j in Hibernate. Download the Eclipse Project of this example : HibernateLog4j.zip

Logging with Logback

So here we are going to see how to integrate the Logback framework with Hibernate. You can actually configure Logback the same way in all Java programms.

1.Download Logback libraries

To work with slf4j and Logback we need, logback-classic-1.0.13.jarlogback-core-1.0.13. As we said Hibernate 4.2.3.Final aytomatically fetches and uses the appropriate versions of core library files of slf4j.

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.javacodegeeks</groupId>
	<artifactId>HibernateMySQLExample</artifactId>
	<packaging>jar</packaging>
	<version>1.0-SNAPSHOT</version>
	<name>HibernateMySQLExample</name>
	<url>http://maven.apache.org</url>

	<!-- JBoss repository for Hibernate -->

	<repositories>
		<repository>
			<id>JBoss repository</id>
			<url>http://repository.jboss.org/nexus/content/groups/public/</url>
		</repository>
	</repositories>

	<dependencies>

		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-core</artifactId>
			<version>4.2.3.Final</version>
		</dependency>

		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>5.1.9</version>
		</dependency> 

		<!-- logback -->
		<dependency>
			<groupId>ch.qos.logback</groupId>
			<artifactId>logback-core</artifactId>
			<version>1.0.13</version>
		</dependency>

		<dependency>
			<groupId>ch.qos.logback</groupId>
			<artifactId>logback-classic</artifactId>
			<version>1.0.13</version>
		</dependency>

	</dependencies>

</project>

2. Create logback.xml configuration file

Go to /src/main/resources folder and create logback.xml file. This is a configuration file when you can specify the form of the output of the logger, as well as the things you want to log and the prefered output of the logs (standard output and log files).

logback.xml:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

 <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
	<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
		<Pattern>%d{yyyy-MM-dd_HH:mm:ss.SSS} %-5level %logger{36} - %msg%n
                </Pattern>
	</encoder>
 </appender>

 <appender name="FILE"
	class="ch.qos.logback.core.rolling.RollingFileAppender">
	<file>F:/nikos7/Desktop/LogbackLogs</file>
	<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
	   <Pattern>%d{yyyy-MM-dd_HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
           </Pattern>
	</encoder>

	<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
		<FileNamePattern>F:/nikos7/Desktop/LogbackLogs.%i.zip</FileNamePattern>
		<MinIndex>1</MinIndex>
		<MaxIndex>30</MaxIndex>
	</rollingPolicy>

	<triggeringPolicy
		class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
		<MaxFileSize>2MB</MaxFileSize>
	</triggeringPolicy>

  </appender>

  <logger name="org.hibernate.type" level="ALL" />
  <logger name="org.hibernate" level="DEBUG" />

  <root level="INFO">
	<appender-ref ref="FILE" />
	<appender-ref ref="STDOUT" />
  </root>

</configuration>

The output of the program would be:

18:07:26,020 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
18:07:26,021 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
18:07:26,021 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/F:/nikos7/Desktop/HibernateMySQLExample/target/classes/logback.xml]
18:07:26,074 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
...
2013-07-14_18:07:26.271 DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration nclob -> org.hibernate.type.NClobType@40f5472d
2013-07-14_18:07:26.271 DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration java.sql.NClob -> org.hibernate.type.NClobType@40f5472d
2013-07-14_18:07:26.271 DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration materialized_clob -> org.hibernate.type.MaterializedClobType@8a7d8b0
2013-07-14_18:07:26.272 DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration materialized_nclob -> org.hibernate.type.MaterializedNClobType@1f6e6127
2013-07-14_18:07:26.273 DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration serializable -> org.hibernate.type.SerializableType@2d00c385
2013-07-14_18:07:26.275 DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration object -> org.hibernate.type.ObjectType@669b675b
2013-07-14_18:07:26.275 DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration java.lang.Object -> org.hibernate.type.ObjectType@669b675b
2013-07-14_18:07:26.276 DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration imm_date -> org.hibernate.type.AdaptedImmutableType@2d8f7705
2013-07-14_18:07:26.276 DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration imm_time -> org.hibernate.type.AdaptedImmutableType@25cf00a1
2013-07-14_18:07:26.276 DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration imm_timestamp -> org.hibernate.type.AdaptedImmutableType@39325d6b
2013-07-14_18:07:26.276 DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration imm_dbtimestamp -> org.hibernate.type.AdaptedImmutableType@19933923
2013-07-14_18:07:26.276 DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration imm_calendar -> org.hibernate.type.AdaptedImmutableType@108c35f3
...
2013-07-14_18:07:26.343 DEBUG o.h.i.util.xml.DTDEntityResolver - Attempting to resolve on classpath under org/hibernate/
2013-07-14_18:07:26.344 DEBUG o.h.i.util.xml.DTDEntityResolver - Located [http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd] in classpath
2013-07-14_18:07:26.357 DEBUG org.hibernate.cfg.Configuration - hibernate.bytecode.use_reflection_optimizer=false
2013-07-14_18:07:26.357 DEBUG org.hibernate.cfg.Configuration - hibernate.connection.driver_class=com.mysql.jdbc.Driver
2013-07-14_18:07:26.357 DEBUG org.hibernate.cfg.Configuration - hibernate.connection.username=root
2013-07-14_18:07:26.357 DEBUG org.hibernate.cfg.Configuration - hibernate.connection.password=
2013-07-14_18:07:26.357 DEBUG org.hibernate.cfg.Configuration - hibernate.connection.url=jdbc:mysql://localhost:3306/tutorials
2013-07-14_18:07:26.357 DEBUG org.hibernate.cfg.Configuration - hibernate.dialect=org.hibernate.dialect.MySQLDialect
2013-07-14_18:07:26.357 DEBUG org.hibernate.cfg.Configuration - show_sql=true
2013-07-14_18:07:26.357 DEBUG org.hibernate.cfg.Configuration - Session-factory config [null] named resource [com/javacodegeeks/Student.hbm.xml] for mapping
2013-07-14_18:07:26.357 INFO  org.hibernate.cfg.Configuration - HHH000221: Reading mappings from resource: com/javacodegeeks/Student.hbm.xml
2013-07-14_18:07:26.374 DEBUG o.h.i.util.xml.DTDEntityResolver - Trying to resolve system-id [http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd]
...
2013-07-14_18:07:26.403 DEBUG org.hibernate.cfg.Configuration - Properties: {hibernate.connection.password=, java.runtime.name=Java(TM) SE Runtime Environment, sun.boot.library.path=C:\Program Files\Java\jre7\bin, java.vm.version=23.7-b01, hibernate.connection.username=root, user.country.format=GR, java.vm.vendor=Oracle Corporation, java.vendor.url=http://java.oracle.com/, path.separator=;, java.vm.name=Java HotSpot(TM) 64-Bit Server VM, file.encoding.pkg=sun.io, user.script=, user.country=US, sun.java.launcher=SUN_STANDARD, sun.os.patch.level=Service Pack 1, java.vm.specification.name=Java Virtual Machine Specification, user.dir=F:\nikos7\Desktop\HibernateMySQLExample, java.runtime.version=1.7.0_17-b02, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, java.endorsed.dirs=C:\Program Files\Java\jre7\lib\endorsed, os.arch=amd64, java.io.tmpdir=C:\Users\nikos7\AppData\Local\Temp\, line.separator=
, java.vm.specification.vendor=Oracle Corporation, user.variant=, os.name=Windows 7, sun.jnu.encoding=Cp1252, java.library.path=C:\Program Files\Java\jre7\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files (x86)\AMD APP\bin\x86_64;C:\Program Files (x86)\AMD APP\bin\x86;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\Windows Live\Shared;F:\QuickTime\QTSystem\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;C:\Program Files (x86)\Windows Kits\8.0\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;F:\Program Files (x86)\SubVersion\bin;F:\nikos7\Desktop\maven-3.0.5\bin;., java.specification.name=Java Platform API Specification, java.class.version=51.0, sun.management.compiler=HotSpot 64-Bit Tiered Compilers, os.version=6.1, user.home=F:\nikos7, user.timezone=Europe/Athens, java.awt.printerjob=sun.awt.windows.WPrinterJob, file.encoding=Cp1252, java.specification.version=1.7, hibernate.connection.driver_class=com.mysql.jdbc.Driver, show_sql=true, java.class.path=F:\nikos7\Desktop\HibernateMySQLExample\target\classes;F:\nikos7\.m2\repository\org\hibernate\hibernate-core\4.2.3.Final\hibernate-core-4.2.3.Final.jar;F:\nikos7\.m2\repository\antlr\antlr\2.7.7\antlr-2.7.7.jar;F:\nikos7\.m2\repository\org\jboss\logging\jboss-logging\3.1.0.GA\jboss-logging-3.1.0.GA.jar;F:\nikos7\.m2\repository\dom4j\dom4j\1.6.1\dom4j-1.6.1.jar;F:\nikos7\.m2\repository\org\jboss\spec\javax\transaction\jboss-transaction-api_1.1_spec\1.0.1.Final\jboss-transaction-api_1.1_spec-1.0.1.Final.jar;F:\nikos7\.m2\repository\org\hibernate\javax\persistence\hibernate-jpa-2.0-api\1.0.1.Final\hibernate-jpa-2.0-api-1.0.1.Final.jar;F:\nikos7\.m2\repository\org\hibernate\common\hibernate-commons-annotations\4.0.2.Final\hibernate-commons-annotations-4.0.2.Final.jar;F:\nikos7\.m2\repository\org\javassist\javassist\3.15.0-GA\javassist-3.15.0-GA.jar;F:\nikos7\.m2\repository\mysql\mysql-connector-java\5.1.9\mysql-connector-java-5.1.9.jar;F:\nikos7\.m2\repository\ch\qos\logback\logback-core\1.0.13\logback-core-1.0.13.jar;F:\nikos7\.m2\repository\ch\qos\logback\logback-classic\1.0.13\logback-classic-1.0.13.jar;F:\nikos7\.m2\repository\org\slf4j\slf4j-api\1.7.5\slf4j-api-1.7.5.jar, user.name=nikos7, hibernate.bytecode.use_reflection_optimizer=false, hibernate.show_sql=true, java.vm.specification.version=1.7, sun.java.command=com.javacodegeeks.App, java.home=C:\Program Files\Java\jre7, sun.arch.data.model=64, hibernate.dialect=org.hibernate.dialect.MySQLDialect, hibernate.connection.url=jdbc:mysql://localhost:3306/tutorials, user.language=en, java.specification.vendor=Oracle Corporation, user.language.format=el, awt.toolkit=sun.awt.windows.WToolkit, java.vm.info=mixed mode, java.version=1.7.0_17, java.ext.dirs=C:\Program Files\Java\jre7\lib\ext;C:\Windows\Sun\Java\lib\ext, sun.boot.class.path=C:\Program Files\Java\jre7\lib\resources.jar;C:\Program Files\Java\jre7\lib\rt.jar;C:\Program Files\Java\jre7\lib\sunrsasign.jar;C:\Program Files\Java\jre7\lib\jsse.jar;C:\Program Files\Java\jre7\lib\jce.jar;C:\Program Files\Java\jre7\lib\charsets.jar;C:\Program Files\Java\jre7\lib\jfr.jar;C:\Program Files\Java\jre7\classes, java.vendor=Oracle Corporation, file.separator=\, java.vendor.url.bug=http://bugreport.sun.com/bugreport/, sun.io.unicode.encoding=UnicodeLittle, sun.cpu.endian=little, sun.desktop=windows, sun.cpu.isalist=amd64}
2013-07-14_18:07:26.410 DEBUG o.h.i.internal.IntegratorServiceImpl - Adding Integrator [org.hibernate.cfg.beanvalidation.BeanValidationIntegrator].
2013-07-14_18:07:26.429 DEBUG org.hibernate.cfg.Configuration - Preparing to build session factory with filters : {}
2013-07-14_18:07:26.436 INFO  o.h.s.j.c.i.DriverManagerConnectionProviderImpl - HHH000402: Using Hibernate built-in connection pool (not for production use!)
2013-07-14_18:07:26.440 INFO  o.h.s.j.c.i.DriverManagerConnectionProviderImpl - HHH000115: Hibernate connection pool size: 20
2013-07-14_18:07:26.440 INFO  o.h.s.j.c.i.DriverManagerConnectionProviderImpl - HHH000006: Autocommit mode: false
2013-07-14_18:07:26.441 INFO  o.h.s.j.c.i.DriverManagerConnectionProviderImpl - HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/tutorials]
2013-07-14_18:07:26.441 INFO  o.h.s.j.c.i.DriverManagerConnectionProviderImpl - HHH000046: Connection properties: {user=root, password=}
2013-07-14_18:07:26.462 DEBUG o.h.s.j.c.i.DriverManagerConnectionProviderImpl - Opening new JDBC connection
2013-07-14_18:07:26.611 DEBUG o.h.s.j.c.i.DriverManagerConnectionProviderImpl - Created connection to: jdbc:mysql://localhost:3306/tutorials, Isolation Level: 4
2013-07-14_18:07:26.611 DEBUG o.h.e.jdbc.internal.JdbcServicesImpl - Database ->
       name : MySQL
    version : 5.5.27
      major : 5
      minor : 5
2013-07-14_18:07:26.611 DEBUG o.h.e.jdbc.internal.JdbcServicesImpl - Driver ->
       name : MySQL-AB JDBC Driver
    version : mysql-connector-java-5.1.9 ( Revision: ${svn.Revision} )
      major : 5
      minor : 1
2013-07-14_18:07:26.611 DEBUG o.h.e.jdbc.internal.JdbcServicesImpl - JDBC version : 3.0
2013-07-14_18:07:26.624 INFO  org.hibernate.dialect.Dialect - HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
2013-07-14_18:07:26.631 INFO  o.h.e.j.internal.LobCreatorBuilder - HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
2013-07-14_18:07:26.654 DEBUG org.hibernate.cfg.Configuration - Processing hbm.xml files
2013-07-14_18:07:26.664 DEBUG org.hibernate.cfg.HbmBinder - Mapping class: com.javacodegeeks.Student -> student
2013-07-14_18:07:26.666 DEBUG org.hibernate.cfg.HbmBinder - Mapped property: studentId -> STUDENT_ID
2013-07-14_18:07:26.670 DEBUG org.hibernate.cfg.HbmBinder - Mapped property: studentName -> STUDENT_NAME
2013-07-14_18:07:26.670 DEBUG org.hibernate.cfg.HbmBinder - Mapped property: studentAge -> STUDENT_Age
2013-07-14_18:07:26.670 DEBUG org.hibernate.cfg.Configuration - Process annotated classes
2013-07-14_18:07:26.671 DEBUG org.hibernate.cfg.Configuration - Processing fk mappings (*ToOne and JoinedSubclass)
2013-07-14_18:07:26.672 DEBUG org.hibernate.cfg.Configuration - Processing extends queue
2013-07-14_18:07:26.672 DEBUG org.hibernate.cfg.Configuration - Processing extends queue
2013-07-14_18:07:26.672 DEBUG org.hibernate.cfg.Configuration - Processing collection mappings
2013-07-14_18:07:26.672 DEBUG org.hibernate.cfg.Configuration - Processing native query and ResultSetMapping mappings
2013-07-14_18:07:26.672 DEBUG org.hibernate.cfg.Configuration - Processing association property references
2013-07-14_18:07:26.672 DEBUG org.hibernate.cfg.Configuration - Creating tables' unique integer identifiers
2013-07-14_18:07:26.672 DEBUG org.hibernate.cfg.Configuration - Processing foreign key constraints
2013-07-14_18:07:26.677 DEBUG org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
2013-07-14_18:07:26.677 DEBUG org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled
2013-07-14_18:07:26.677 DEBUG org.hibernate.cfg.SettingsFactory - JDBC batch size: 15
2013-07-14_18:07:26.677 DEBUG org.hibernate.cfg.SettingsFactory - JDBC batch updates for versioned data: disabled
2013-07-14_18:07:26.677 DEBUG org.hibernate.cfg.SettingsFactory - Scrollable result sets: enabled
2013-07-14_18:07:26.677 DEBUG org.hibernate.cfg.SettingsFactory - Wrap result sets: disabled
2013-07-14_18:07:26.677 DEBUG org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): enabled
2013-07-14_18:07:26.677 DEBUG org.hibernate.cfg.SettingsFactory - multi-tenancy strategy : NONE
2013-07-14_18:07:26.677 DEBUG org.hibernate.cfg.SettingsFactory - Connection release mode: auto
...
2013-07-14_18:07:26.924 DEBUG org.hibernate.SQL - insert into tutorials.student (STUDENT_NAME, STUDENT_Age) values (?, ?)
Hibernate: insert into tutorials.student (STUDENT_NAME, STUDENT_Age) values (?, ?)
2013-07-14_18:07:26.935 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [1] as [VARCHAR] - JavaFun
2013-07-14_18:07:26.935 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [2] as [VARCHAR] - 19
2013-07-14_18:07:26.938 DEBUG o.h.id.IdentifierGeneratorHelper - Natively generated identity: 65
2013-07-14_18:07:26.941 DEBUG o.h.e.t.spi.AbstractTransactionImpl - committing
2013-07-14_18:07:26.942 DEBUG o.h.e.i.AbstractFlushingEventListener - Processing flush-time cascades
2013-07-14_18:07:26.942 DEBUG o.h.e.i.AbstractFlushingEventListener - Dirty checking collections
2013-07-14_18:07:26.944 DEBUG o.h.e.i.AbstractFlushingEventListener - Flushed: 0 insertions, 0 updates, 0 deletions to 1 objects
2013-07-14_18:07:26.944 DEBUG o.h.e.i.AbstractFlushingEventListener - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
2013-07-14_18:07:26.945 DEBUG o.h.internal.util.EntityPrinter - Listing entities:
2013-07-14_18:07:26.945 DEBUG o.h.internal.util.EntityPrinter - com.javacodegeeks.Student{studentId=65, studentName=JavaFun, studentAge=19}
2013-07-14_18:07:26.948 DEBUG o.h.e.t.i.jdbc.JdbcTransaction - committed JDBC Connection
Great! Student was saved

This was an example on how to use SLF4J with log4j in Hibernate. Download the Eclipse Project of this example : HibernateLogback.zip

Related Whitepaper:

Java Essential Training

Author David Gassner explores Java SE (Standard Edition), the language used to build mobile apps for Android devices, enterprise server applications, and more!

The course demonstrates how to install both Java and the Eclipse IDE and dives into the particulars of programming. The course also explains the fundamentals of Java, from creating simple variables, assigning values, and declaring methods to working with strings, arrays, and subclasses; reading and writing to text files; and implementing object oriented programming concepts. Exercise files are included with the course.

Get it Now!  

Examples Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use
All trademarks and registered trademarks appearing on Examples Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Examples Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.

Sign up for our Newsletter

15,153 insiders are already enjoying weekly updates and complimentary whitepapers! Join them now to gain exclusive access to the latest news in the Java world, as well as insights about Android, Scala, Groovy and other related technologies.

As an extra bonus, by joining you will get our brand new e-books, published by Java Code Geeks and their JCG partners for your reading pleasure! Enter your info and stay on top of things,

  • Fresh trends
  • Cases and examples
  • Research and insights
  • Two complimentary e-books
Get tutored by the Geeks! JCG Academy is a fact... Join Now
Hello. Add your message here.