-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: How to log or get the class where the query comes from
PostPosted: Wed Mar 30, 2016 8:53 pm 
Newbie

Joined: Wed Mar 30, 2016 5:56 pm
Posts: 1
Hi,

Is there a way/technique to log/get the class that executes a query (the class that contains the sessionfactory)?

For example, given :
Code:
class MyClass {

method1() {
      MyObject o;
      ................
      sessionFactory.getCurrentSession().save(o);
}

method2() {
      ................
      Query query =  sessionFactory.getCurrentSession().createQuery("FROM MyObject....");
      query.list();
}

}


What I want is to be able to produce a log like this:
Code:
-    MyClass.java:20  insert into my_object values .......
-    MyClass.java:50  select from my_object ........


Any hint ? maybe with log4j? or with an interceptor? (suppose there is no access to the source code of MyClass)


Thanks!


Top
 Profile  
 
 Post subject: Re: How to log or get the class where the query comes from
PostPosted: Thu Mar 31, 2016 12:26 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
All log providers offer that, and that works only for queries.
For insert/update/delete statements, Hibernate works with entity-state transitions so changes accumulate in an Action Queue and are executed during flush mode, so you don;t know in which DAO the statement associated entity state transitions has originate.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.