-->
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.  [ 12 posts ] 
Author Message
 Post subject: How to Intercept SQL in Hibernate
PostPosted: Thu Nov 10, 2005 7:02 am 
Newbie

Joined: Mon May 30, 2005 5:52 am
Posts: 15
Hi,
I am woudering if it is possible to intercept the SQL before it is set to the database. Reason is I am trying to use EXPLAIN to analyse SQL in POSTGRES. In order to do this I have to append EXPLAIN to the start of each query going to the database. Is there a mechanism for doing somthing like this in hibernate.
thanks,
Richie.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 10, 2005 7:08 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Interceptor.prepareSQL() in 3.1

but adding EXPLAIN while the program runs wont solve anything since hibernate expects to get a result back - not some eXPLAIN result.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 10, 2005 7:37 am 
Newbie

Joined: Mon May 30, 2005 5:52 am
Posts: 15
Thanks for that. The EXPLAIN will return results - but has the added bonus of writing EEXPLAIN information about the query to a postgres log file.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 10, 2005 7:47 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
ah - didn't know postgress could do that, nice.

then Interceptor.prepareSQL() is your savior ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 10, 2005 8:08 am 
Newbie

Joined: Mon May 30, 2005 5:52 am
Posts: 15
Hi Max - Im guessing that this method is'nt available in 3.0. Can't find it anyway. If im using 3.0 is there any way around this.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 10, 2005 8:22 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
not really, but you can go to AbstractBatcher and you can edit the sql there (you will need to patch it in your own version)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 10, 2005 8:31 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Just wrapp driver and intercept it in JDBC level.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 10, 2005 8:33 am 
Newbie

Joined: Mon May 30, 2005 5:52 am
Posts: 15
Yeah,
I think that is what I am going to do. Had started down that road but though Hibernate would have somthing. Unfortunatly we have not upgraded to 3.1 yet so I will do with this.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 10, 2005 9:11 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
BTW
if you need query plan only then you can configure postgresql to print it to log without any SQL interception (see debug and profiling options).


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 10, 2005 9:13 am 
Newbie

Joined: Mon May 30, 2005 5:52 am
Posts: 15
Thanks - Im aware of this. Hibernate also can print the query plan. But I need the Analysis information as well.
Cheers.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 11, 2005 3:16 pm 
Newbie

Joined: Tue Aug 30, 2005 4:43 pm
Posts: 8
Is it Interceptor.prepareSQL() or prepareStatement()? I'm using the latest 3.1 code but I don't see the prepareSQL method within the Interceptor interface. Am I missing something basic here? Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 11, 2005 3:22 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
its prepareStatement

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 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.