i`m trying to map a collection.
Code:
/**
* @hibernate.class
*/
public class BClass {
private long id;
private List test;
/**
* @hibernate.id generator-class="native"
*/
public long getId() {
return id;
}
/**
* @hibernate.list lazy="false" cascade="all"
* @hibernate.collection-key column="parent_id"
* @hibernate.collection-one-to-many class="hibernate.test.AClass"
* @hibernate.collection-index column="name"
*/
public List getTest(){
return test;
}
and the test class
Code:
AClass a = new AClass("testing");
BClass b = new BClass();
java.util.List s = new java.util.ArrayList(1);
s.add(a);
b.setTest(s);
session.save(b);
the problem is that on session.save, hibernate first inserts the BClass (wich works just fine) but then tries to update the AClass (o pojo with only hibernate properties), wich shoud be also inserted and not updated (it doesn`t exist in the database).
if the hbm file are required i can provide them.
(I`m using hibernate 2.1 with xdoclet 1.2.1)
And one final thing: Is it possible to have a unique many-to-one association and have the cascade insert/update/delete? Like just say in AClass i would have
Code:
/**
* hibernate.many-to-one outer-join="true" cascade="all" column="b_id" unique="true"
*/
public BClass getB() {
return b;
}
and the when i do an update on a to have the asociated b class updated?