Forums Register Login

Hibernate one-to-one link table mapping + design suggestion

+Pie Number of slices to send: Send
Hi ranchers,

I'm facing some difficulty mapping a one-to-one relationship on a link table. I'm not entirely sure what the best way to go about this is...so any suggestions on mapping or alternative design would be most welcome.

If we imagine this scenario. Let's say we have a table Product and a table PriceFormula. These tables are completely independant of each other. However, a product MAY have a reference to a single PriceFormula (but not always). Therefore, my design would be not to have a reference in the Product table (as not all products will need it) but to introduce a third (link) table ProductPriceFormula. ProductPriceFormula would share the same primary key as Product.

So ProductPriceFormula table would have say two fields ProductID and PriceFormulaID.

In hibernate i'm thinking that ProductPriceFormula would need to be represented as an object? Is this correct? So i couldn't just put a PriceFormula object in the Product object...instead i would need to create a ProductPriceFormula object and hold a reference to that in Product?

I'm thinking my ProductPriceFormula class would look like:

class ProductPriceFormula
{
private Product product;
private PriceFormula priceFormula;

//Getters & Setters
}

Assuming all of the above makes sense...how would one then map this class in hibernate?

I'm thinking the product class mapping would have something like this in for the ProductPriceFormula:

<one-to-one name="productPriceFormula" class="ProductPriceFormula" cascade="save-update"/>

However i can't seem to get the ProductPriceFormula class mapping right

Any tips or comments would be greatly appreciated, thanks!
+Pie Number of slices to send: Send
Hi Marcus
Have a look at this use cases. It doen have a one to one relationship based on foreign key constraint
The only thing to take care of is the use cases have no exception handling which you can put it in your code.
http://www.makemyinfo.com/Tutorial.do?action=getTutorial&tutId=T0005.jsp

Thanks
Rashid
The world's cheapest jedi mind trick: "Aw c'mon, why not read this tiny ad?"
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 971 times.
Similar Threads
IBM Test: Coupling question
Hibernate Mapping & POJO Inheritance & Composition
one to many mapping
How to lazily load references when the object is detached from session ?
Optimum Hibernate Mapping for a Tree Model
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 04:10:22.