Hibernate maintains statistics on which objects were queried, and how often
– Enable statistics in the configuration file
• hibernate.generate_statistics=true
Hibernate Interfaces
– Statistics for global information
– EntityStatistics for info on Object Type
– QueryStatistics for SQL and HQL queries
I think you require logging for timestamp not stats, but you can use any of the below options as per your requirements.
You can use log4jdbc JDBC proxy driver for logging SQL and other interesting information.
You can use slf4j-api.jar in your classpath together with the jar file for your preferred binding - slf4j-log4j12.jar
To use Log4j you will also need to place a log4j.properties file in your classpath. An example properties file is distributed with Hibernate in the src/ directory.
Hibernate Log Categories
org.hibernate.SQL -
Log all SQL DML statements as they are executed
org.hibernate.type - Log all JDBC parameters
org.hibernate.tool.hbm2ddl - Log all SQL DDL statements as they are executed
org.hibernate.pretty - Log the state of all entities (max 20 entities) associated with the session at flush time
org.hibernate - Log everything. This is a lot of information but it is useful for troubleshooting
with Hibernate, you should almost always work with debug enabled for the category org.hibernate.SQL, or, alternatively, the property hibernate.show_sql enabled
<attribute name="ShowSqlEnabled">true</attribute>
- With enabling Statistics , for example you can get total no of counts for a particular entity class cat stats. (How many times insert, update or delete called) like below:
EntityStatistics entityStats =
stats.getEntityStatistics( Cat.class.getName() );
long changes =
entityStats.getInsertCount()
+ entityStats.getUpdateCount()
+ entityStats.getDeleteCount();
log.info(Cat.class.getName() + " changed " + changes + "times" );
- `String hql = "from POJO as POJO where to_date(to_char(POJO.tradeDate, 'DD-MON-YY'), 'DD-MON-YY') = :date";
Query query = getSession().createQuery(hql);
query.setParameter("date", date);
`
Please check Hibernate Documentation for more details.