-->
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.  [ 1 post ] 
Author Message
 Post subject: Intercept with Interceptor class the values from a query
PostPosted: Fri May 15, 2015 3:33 pm 
Newbie

Joined: Fri May 15, 2015 3:55 am
Posts: 2
Hi everyone,sorry for the long topic, I started working with hibernate for a couple of weeks, so if I missed an obvious solution written in the documentation I apologize. I tried to use the interceptor class of hibernate for a specific task,after the "classic" command :
Code:
List<T> list =  criteria.list();

i want to read before the invocation of the
Code:
getEntity()
method from the interceptor class of hibernate,the values and columns of the result (you can see that like the result set from a classic sql query).
So i tried to use the method
Code:
onPrepareStatement();
(always from interceptor class) and i can catch the prepared statement builded from hibernate, so i can change the column ^^ and this is done.
No i'm try to catch the value for each column before the invocation of the
Code:
getEntity()
. A example for why i want this?
Given for a example the java object: Obj(Integer doc_id,URL url,String city);
on the database i have on the "url" column some value with protocol "http://" e some value without. So when i invoke the getEntity method on the interceptor the process launch the "MalformedUrlException" for the values without protocoll. So i just want to check if the url value has the protocol and if don't have make a append on the value.tostring(). I put a piece of code for make myself more clear on what i want to do:
NOTE 1:I know the following is a prepared statement and i can't capture the actual value of the columns, But I have shown this example just to give an idea of what I need to do.
Code:
public String onPrepareStatement(String sql) {
        System.out.println("onPrepareStatement: Called for statement: " + sql);
        //The SQL in input is like this:
        //onPrepareStatement: Called for statement:     
        //select this_.doc_id as doc_id1_1_0_, this_.city as city2_1_0_
       
        //What i want is read->modify->return the SQL to Hibernate:

        //[READ]select "doc_id" as doc_id1_1_0_, "city" as city2_1_0_
        //read the actual value associated a the columns...   
        //[MODIFY]select "doc_id2" as doc_id1_1_0_, "city2" as city2_1_0_
        //...change these values...
        //[RETURN]select this_.doc_id as doc_id1_1_0_, this_.city as city2_1_0_
        //...return the ne prepared statement to the getEntity() methhod but with     
        //new value for the param
        return sql;
    }
//... invoke the getEntity method

NOTE 2:I know i can just use SQL\HQL native query or get the resutl set in other
ways but i just can't touch the project so i can only intercept the response,
changed and return to the project.
Ty in advance for any help.


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

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.