Hibernate Debugging
Debugging Hibernate application tends to be tricky as there is a time lag between application issuing a calls on hibernate api and hibernate issuing SQL to the database.We will look into various strategies to look into how to debug hibernate.Configuration
Enable show_sql property in the hibernate configuration file. In your hibernate.cfg,xml put the following
<!-- Log out all the sql that hibernate is issuing to datbase. This is very useful for debugging --> <property name="show_sql">true</property>
This will flush all the sql that hibernate issues to databae. For example in Hibernate Introduction with Annotation example you will see in the console
Hibernate: insert into Student (STUDENT_ID, name) values (null, ?)
Enable format_sql to format the generate sql. However this will take more space. Change in hibernate.cfg.xml
<!-- Format the logged sql --> <property name="format_sql">true</property>
In the console
Hibernate: insert into Student (STUDENT_ID, name) values (null, ?)
To understand the origin of SQL, hibernate can put comments which can be enabled by putting the following property in hibernate.cfg.xml
<!-- Show comment --> <property name="use_sql_comments">true</property>
In the console
Hibernate: /* insert com.oyejava.Student */ insert into Student (STUDENT_ID, name) values (null, ?)
Enabling log4j
Enabling logging level in log4j.properties can provide more information about the internal of application. Copy the sample log4j.properties from hibernate core download at etc folder. Run the application and you will tons of information about internals of hibernate. Tweak the level in log4j.properties. Enabling log4j.logger.org.hibernate.type at debug level will show the bind parameters. Do the following in log4j.properties. The following line is already there, you have to uncomment it.
log4j.logger.org.hibernate.type=debug
In the console
Hibernate: insert into Student (STUDENT_ID, name) values (null, ?) 16:04:15,440 DEBUG StringType:133 - binding 'oyeJava' to parameter: 1
Debugging Source
The hibernate download comes with the source code. The src folder in the download has all the source. For hard to solve problems you can start digging into the source code itself. In eclipse you can do it as follows:
- Go to Project properties by right clicking on project name in navigator view and than click on Properties.
- Go to Java Build Path -> Source
- Click on Link Source
- In the Linked Folder location and pick the location of hibernate source till src
- In the folder name give a name which does not conflicts with your present source location.
- Click on Finish and than Ok. You can now put break point in the application and can go the hibernate code.
Back to Hibernate Index
Back To Java Home
Back To Home
Sidebar
Last wiki comments
- Introduction to ORM: ugg boots
- Introduction to ORM: ugg boots
- AOP: Thanks
- Lalit Bhatt: Superb Collection
- Lalit Bhatt: J2EE training
- Introduction to ORM: timberland shoes
- Introduction to ORM: jordan shoes
- Introduction to ORM: nike air max
- Pune Tourist Spots: KONARK PARK CLOSED
- jQuery Form Validations: Jquery Developer
Sidebar
Random Pages
- What markets work on?
- Why projects fail?
- Bharat Band - Jai ho
- The concept of Nation
- Don't hide complexity if it cannot be handled in a robustway
Last blog post comments
-
Prospective MLA for Pune election - 2009: ugg boots
Wed 01 of Sep., 2010 12:58 IST
-
Bharat Band - Jai ho: How do we protest?
Wed 18 of Aug., 2010 13:13 IST
-
Divided by Destiny: Contact
Fri 23 of July, 2010 16:02 IST
-
Future of Java: thesis writing
Sat 17 of July, 2010 01:50 IST
-
Hang till Death Mr. Kasab: some change
Mon 28 of June, 2010 16:03 IST
-
God Religion : Why we are confused?: Re: Is GOD Necessary?
Tue 15 of June, 2010 17:29 IST
-
God Religion : Why we are confused?: Is GOD Necessary?
Tue 15 of June, 2010 13:06 IST
-
The reason in religion: good
Wed 10 of Mar., 2010 18:30 IST
-
The confusion of Design Patterns: I think at macro level you are right...
Tue 23 of Feb., 2010 03:31 IST
-
The Indian Municipality: Comment
Fri 22 of Jan., 2010 13:20 IST
Post new comment