Hello, I'm kind of new to hibernate and I was trying basics examples with no real problem so then I did a little database on my own but there is a thing I want to do that I've never seen explained nowhere and that might be possible but my level doesn't allow me to find for now.
Here is the general relation table :
[img]
http://nerae.free.fr/general-model.jpg
[/img]
And the UML model :
[img]
http://nerae.free.fr/uml-model.jpg
[/img]
Here are my classes :
Product.java :
Quote:
public class Product {
private int id;
private String description;
private double prize;
public Product() {
}
....
Standards get and set methods
....
}
}
Product.hbm.xml
Quote:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<class name="Product" table="PRODUCTS">
<id name="id" type="int" unsaved-value="null">
<column name="id" sql-type="int" not-null="true" />
<generator class="uuid.hex" />
</id>
<property name="description"/>
<property name="prize"/>
</class>
</hibernate-mapping>
Order.java
Quote:
import java.sql.Date;
import java.util.HashSet;
import java.util.Set;
public class Order {
private String id;
private Date order_date;
private double final_cost;
private boolean order_confirmed;
private Set product_ordered = new HashSet();
public Order() {
}
....
Standards get and set methods
....
public Set getProduct_ordered(){
return product_ordered;
}
public void setProduct_ordered(Set product_ordered){
this.product_ordered=product_ordered;
}
}
Order.hbm.xml :
Quote:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<class name="Order" table="ORDERS">
<id name="id" type="string" unsaved-value="null">
<column name="id" sql-type="char(32)" not-null="true" />
<generator class="uuid.hex" />
</id>
<property name="order_date" type="timestamp"/>
<property name="final_cost"/>
<property name="order_confirmed"/>
<set name="product_ordered" table="product_ordered">
<key column="orders_id"/>
<many-to-many column="product_id" class="Product"/>
</set>
</class>
</hibernate-mapping>
But then I need to add the quantity element in this relation but I don't know How to do ^^;
May I have to create a class for product_id and define two many-to-one relations ? Didn't it exist a mean to add an elemnt or property into the set declaration ? Maybe create a class wich is an extend of a Set and can implement two element a the same time ? or store the both product_id and quatity value associated in some kinf of vector object ? but then how to map it into hibernate ? ^^;
Please if someone has a solution for this problem I will be very glad.
Thanks.
[/quote]