On 4/20/07, Jason Brice <[EMAIL PROTECTED]> wrote:

>> However if would still like to use Hibernate for your read-only DB2
data, make sure you're using Hibernate's StatelessSession API or else you'll
just be paying a huge CPU and memory overhead using Hiberanate.

Hi Sanjiv,

Is there a way to use the StatelessSession API and still have Spring
managing the session?


Just get the SessionFactory from the Hibernate Session passed to the
HibernateCallback and from there create the StatelessSession.

getHibernateTemplate().execute(new HibernateCallback() {

           public Object doInHibernate(Session session) throws
HibernateException, SQLException {
               StatelessSession statelessSession =
session.getSessionFactory().openStatelessSession();

               ScrollableResults customers = session.getNamedQuery
("GetCustomers").scroll(ScrollMode.FORWARD_ONLY);
               while ( customers.next() ) {
                   Customer customer = (Customer) customers.get(0);
                   customer.updateStuff(...);
                   statelessSession.update(customer);
               }
               return null;
           }
       });


I've got three Spring managed datasources... one of them is only ever used
to grab a sequence value out of an Oracle db, which sounds like a big waste
of resources. But I'd like to keep all the config stuff in one spot and
don't yet see an obvious way to do this with the StatelessSession API.

Any pointers appreciated.
Jason


Reply via email to