views:

858

answers:

3

I have an entity that maps to an external oracle table which is one of the primary data sources of my application. This entity is modelled using hibernate.

The oracle table now has a complex function defined the calculates some special values. I need to call this funtion somehow - almost as another accessor on the entity.

What would you suggest is the best way to incorprate this function call so that I can maintain relatively normal hibernate access to the entities ?

A: 

You could call the function directly using a stored procedure with HQL. Unless, of course, you're going to have to call this function for every entry in the table. But if you do it within the same hibernate session, as long as you aren't doing to many calls at the same time, this should work without a significant performance hit.

Elie
I need to call it for every entry in the table. This entity is processed from beginning to end so it would be good to have a way to put the function call in as part of the natural read.The sql is something like this : SELECT FIELD1, FIELD2, FUNCTION(FIELD1) from DataTable
LenW
A: 

I have a solution using the @Formula annotation

LenW
+1  A: 

In order to keep the decoupling from your database, provided by Hibernate, I would rely on Oracle to invoke this function, using triggers or views.

The main advantage of this approach is that it is totally seamless to your Hibernate implementation.

DouglasJose
how would u do that with a function that requires parameters ?
LenW