My question is around query/database design. What I am running into could be bad schema design, however we are not in a position to re-design at this stage of the game. Also just thinking about it what I am about to describe is probably a valid use case.
As I am creating queries for our object graph I end up writing the same thing over and over again, based on what table/object my graph navigation starts with.
For Example:
We have tables where
A is a main table
B is a table holding different data with a foreigh key to A, where A 1..1 B
C is another table holding foreign key to A where A 1..n C
so if I write queries where I need to start with B's, I also need to fetch A, same goes for C's. In both cases I have to write the same exact thing to load A. Example below illustrates this.
from C c
join fetch c.a a
join fetch a.someobject // identical
etc // identical
where some criteria
from B b
join fetch b.a a
join fetch a.someobject // identical
etc // identical
where some criteria
Is there any way in hibernate to reuse existing query for a specific object in another query, so if I had
from A
join fetch someobject
etc
I could link my queries for C, and B above to a single query that I already have for object A that will load everything necessary.
I hope this makes sense.
|