Product is mapped to a table PRODUCT which has PRODUCTID as PK.
ProductBasic is mapped to a table PRODUCTBASIC which has PRODUCTID,USETYPE and STARTTTIMESTAMP as composite key. Also PRODUCTID
is the foreign key referencing PRODUCT table...
How can i define my one-to-one mapping considering ProductBasic.productId should get its value from Product.productId
posted 11 years ago
Actually Product and ProductBasic have one-to-many relationship at database side, but logically i made it to one-to-one (using endTimeStamp column) as:
ProductId 1 has many rows in ProductBasic but i am only interested in one row whose startTimeStamp<currentTime><ENDTIMESTAMP
(whose endTimestamp = 31-12-9999) only.... Hence while retriving i will always get 1 row....
Actually when one row is inserted in ProductBasic it is inserted (with endTimeStamp always as 31-12-9999) as:
PRODUCTID USETYPE STARTTIMESTAMP ENDTIMESTAMP
3 1 01-01-2009 31-12-9999
Whenever this row is modified, we modify the EndTimeStamp of current row (as endtimeStamp=currentTimeStamp) and insert another row (with
starttimestamp=currentTimestamp and endtimestamp=31-12-9999) as:
So every product in ProductBasic table has only one row as active (whose endtimestamp=31-12-9999)....
How can i define this logical one-one-one relationship in Hibernate and retrieve and save proper data....>
Not so fast naughty spawn! I want you to know about
Devious Experiments for a Truly Passive Greenhouse!