Showing posts with label ORM. Show all posts
Showing posts with label ORM. Show all posts

Monday, October 10, 2016

Hibernate show sql with parameter values

In this article i will show you "How to log the SQL with parameters in Hibernate?"

As we know Hibernate is ORM framework which is being used at persistence layer. If you are a developer and you are Woking on development environment than i guess you faced a challenge to debug the SQL statement. 


Hibernate gives us a feature to show sql in the logs 



But the above feature doesn't let see the parameters which you are passing into your SQL statement. 


Hibernate provides 2 category and levels to execute the SQL parameters and show their bind parameters.


1. Use org.hibernate.SQL as debug

2. org.hibernate.type.descriptor.sql as trace

Here is the code snippet of log4j : - 



Please have look on the logs where you can see the actual parameters are being printed 




Employee entity used in the code : - 




Main class : - 




Summary :-


So using "log4j.logger.org.hibernate.SQL=debug" and "log4j.logger.org.hibernate.type.descriptor.sql=trace" we can easily log SQL parameters. With these features it is really easy to trouble shoot or debug the issue on development environment. But always remember it is always being advisable in the development or sand box environment. Please do not use this features on production environment because it will generate a lot of unnecessary logs and may creak disk space issue in the long run.

Thursday, July 16, 2015

What is Hibernate ORM(object-relational mapping)?

Hibernate ORM ( Object Relational Mapping) in the short form called as Hibernate is a framework which is being used for performing all the tasks which are related to Database operations.
So seems like quite complex but do not worry just go through the following points and than you will get to know more above Hibernate : -
  1. OOP : -Main aim of hibernate is to convert the basic SQL queries and operations which we do into the Object Oriented Paradigm.
  2. JAVA POJO(Plain Old Java Object) : - All of your database table will be represented with the JAVA class know as POJO(Plain Old Java Object)
  3. NO SQL : - So you do not have to deal with SQL queries all you need is to play with the JAVA POJO classes.
  4. HQL(Hibernate Query Language) : -Hibernate provides HQL (Hibernate Query Language) which is much a like SQL(Structured Query Language) for writing the database queries for performing Database operations.
  5. INTEGRATION : – Hibernate is quite good at integration and it can be integrated with any JAVA, JAVA EE, EJB, JBI application.
If you are new to the Hibernate and beginner in the JAVA than it will look like a lot in your plate to eat. But do not worry we will have each bite one by one. So seat tight we have lot of topics which will explain you how to start working with the Hibernate.