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!