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: Can You Intercept loading of objects from the database?
PostPosted: Wed Jan 04, 2006 2:41 pm 
Newbie

Joined: Wed Sep 14, 2005 12:17 pm
Posts: 13
Hibernate version: 3.0.1

Name and version of the database you are using: DB2 for z/OS v7


We've been trying to optimize the performance of some parts of our application, and we were wondering if it's possible to configure Hibernate with some type of handler or interceptor that gets invoked at the moment that Hibernate tries to load certain items from the database. Here's a practical example:

First, it's worth mentioning that for the vast majority of our use of the database, we're doing read-only operations against a legacy database, and have configured our mapping files to say mutable="false".

In the environment we're working in, it's difficult to change the legacy database (we don't control; other applications use it, etc.), and it's much easier (from a process perspective) to do radical things with our Hibernate configurations than it is to do simple things with the database schema.

We have a relationship like so (names changed to protect the innocent):

Imagine three entities: StudentEnrollment, Course and Textbooks. A StudentEnrollment has a relationship to one Course (but a Course can be related to multiple StudentEnrollments) and a Course can have many Textbooks.

In our database, Course is a trivial table. It contains a course number and nothing more. It's also an unfathomably slow table to issue queries against (really, it's a badly-defined view).

In our current environment, we find we have a lot of queries that look like this:

Code:
SELECT this.COURSENO
FROM COURSE this
WHERE this.COURSENO = ?
OR this.COURSENO = ?
OR this.COURSENO = ?


In short, this query ends up resolving the exact same set of course numbers that we started with. Since COURSE is such a performance-affecting entity to work with, we're wondering if there's some way to intercept Hibernate's decision to hydrate the Course objects from the database, and provide some custom, user-written code that provides an alternative mechanism for providing the Course instances.

UserTypes don't seem to be the answer, because UserTypes expect that you're going to interpret the result-set in user-defined ways. What we want is something that takes place instead of issuing the query and interpreting the result set.


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.