Consider this scenatio :
I have one-to-one relation between Product and ProductBasic BUT at database level i have one-to-many between
PRODUCT and PRODUCTBASIC tables as history is mainted in the same table :
Now while querying for ProductBasic, i will always fetch the row which satisfies the condition STARTTIME<CURRENTTIME><ENDTIME
and this will surely return me only one row.
Ideally the generated sql query should be :
select * from PRODUCT product left outer join PRODUCTBASIC productbasic on '100'=productbasic.USETYPE
and '09-MAY-2009 10:00'<productbasic.ENDTIME
Anyway, I think I understand the problem and I had recently the same. A simple solution to integrate this with O/R mapping based on JPA or Hibernate is to use named queries with which you can exactly define this kind of "filter" to get a specific version of an entity by defining a EJBQL query corresponding to the SQL statement you have given.
This is not exactly as nice to use as getting an entity simply by its primary key but it's surely better than using native SQL queries.
posted 11 years ago
I think we are on different page.
Hibernate says, "With clause" with Fetch is not allowed, use Filters. BUT filters (<filter>)are not allowed with one-to-one associations.
May i know the solution in HQL?
He's dead Jim. Grab his tricorder. I'll get his wallet and this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!