-->
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.  [ 6 posts ] 
Author Message
 Post subject: Returning ScrollableResults using Spring
PostPosted: Thu Mar 25, 2004 6:25 am 
Regular
Regular

Joined: Fri Nov 07, 2003 6:31 am
Posts: 104
Location: Beijing, China
Hi everyone,

i'm facing a big issue in the use of Spring.
For some reason, there's a query I need that can't be fetched into persistent objects.
I can't avoid to return a ScrollableResults.
Since getHibernateTemplate() doesn't provide any methods able to return a ScrollableResults I'm kind of stuck there.

Would applying AOP Interceptor a solution to my pb?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 25, 2004 8:26 am 
Senior
Senior

Joined: Wed Aug 27, 2003 6:04 am
Posts: 161
Location: Linz, Austria
In such cases, implement a HibernateCallback, and execute it with HibernateTemplate's generic execute method. You can do anything you like with the Hibernate Session there, still properly participating in Spring's resource and transaction management. You do not need to close the Session in a finally block or the like: HibernateTemplate will do this for you.

Code:
Object result = hibernateTemplate.execute(
  new HibernateCallback() {
    public Object doInHibernate(Session session) throws HibernateException {
      ...
      return ...;
    }
  }
);


Juergen


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 25, 2004 9:19 am 
Regular
Regular

Joined: Fri Nov 07, 2003 6:31 am
Posts: 104
Location: Beijing, China
All right, that's really helpful!!

but i did implement an AOP interceptor by that time, which is really nice I must say.

So what's the big avantage of AOP interceptor over hibernate template except being able to throw checked exception?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 25, 2004 9:26 am 
Senior
Senior

Joined: Wed Aug 27, 2003 6:04 am
Posts: 161
Location: Linz, Austria
HibernateTemplate and HibernateInterceptor basically offer the same level of resource management, just in a different style. HibernateInterceptor's main advantage is indeed that your data access code can throw any checked exceptions.

Juergen


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 25, 2004 9:58 am 
Regular
Regular

Joined: Fri Nov 07, 2003 6:31 am
Posts: 104
Location: Beijing, China
And performance wise, are interceptors slowing down during the runtime in any manner?
Or can you neglect that?
Or is it even faster?

(Sorry it might be a stupid question but i'm really new to AOP)


Last edited by nodje on Tue Jun 03, 2008 5:37 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 25, 2004 10:32 am 
Senior
Senior

Joined: Wed Aug 27, 2003 6:04 am
Posts: 161
Location: Linz, Austria
If you register the interceptor for a target that doesn't need to be proxied otherwise, it will slow down invocations to some degree. But this is neglectable for non-trivial methods: Consider all the work that your data access operation initiates, going through Hibernate and your JDBC driver...

As it doesn't involve proxy setup and offers a lot of convenience methods, I recommend to use HibernateTemplate: With custom HibernateCallback implementations, you should be able to cover any sort of data access operation on a Hibernate Session.

Juergen


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