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.