Hi to all,
I cannot find any attribute in the <class> or <property> element that will allow me to map the data from an indirectly related table to a variable in a Class.
I have the following database design:
ProductSizeJunction table is needed for the many-to-many relationship between Product and Size.
If I have the following class - DetailedProduct class:
Code:
public class DetailedProduct implements Comparable<DetailedProduct>, Serializable {
private long id;
private Product product;
private Size size;
private Color color;
private float width;
private float length;
private float height;
private float weight;
private float girth;
private long otherDetailedProductData;
//constructor;setters;getters;equals;hashCode
}
How can I map the variables width, length, height, weight, girth to the columns with the same name from the table ProductSizeJunction?As you can see in the following mapping file, the DetailedProduct Class is tied to the DetailedProdcut table which in turn is indirectly related to ProductSizeJucntion table,
but I don't know how to specify that:
Code:
<class name="DetailedProduct" table="DetailedProduct">
<id name="id" column="id">
<generator class="native" />
</id>
<many-to-one name="product" class="Product" column="productId"/>
<many-to-one name="size" class="Size" column="sizeId"/>
<many-to-one name="color" class="Color" column="colorId"/>
<property name="otherDPData" type="string" not-null="true"/>
<property name="width" type="float" ?????????????????????? />
</class>
If I think of the database design, I always get to the point where I cannot merge the DetailProduct and the ProductSizeJunction because that way the database wouldn't be normalized. On the other side if I would use a plain JDBC SQL, I could insert or select the width through the productId and sizeId.
How do I do it through Hibernate? Or maybe I have some mistake in the deduction!? Anyway, I would appreciate it a lot if someone gives me a tip to where I can read about this. Till now I had no luck with the reference (or I don't know where to look at). :(
The rest of the classes, although they bear no importance in this case, here they are:
The Product class:
Code:
public class Product implements Comparable<Product>, Serializable {
private long id;
private long otherProductData;
//constructor;setters;getters;equals;hashCode
}
The Size class:
Code:
public class Size implements Comparable<Size>, Serializable {
private long id;
private long otherSizeData;
//constructor;setters;getters;equals;hashCode
}
The Color class:
Code:
public class Color implements Comparable<Color>, Serializable {
private long id;
private long otherColorData;
//constructor;setters;getters;equals;hashCode
}
Kind Regards,
Despot