Hibernate version:2.1.6
Hi,
I know it's a basic stuff what im about to ask but I cannot understand this ......
I have ClassA containing ClassB and what I need is, that when creating class A It will insert 2 records (classA table and ClassB table)
ClassA (has no id property)
private x
private y
private classBinstance ClassB
ClassB
private id
private z
tables:
Code:
TABLE ClassA
CLASSA_ID char(32),
X ...
y...
TABLE ClassB
CLASSB_ID number(10),
CLASSA_ID char(32),
Z...
mapping:
Code:
<class name="ClassAr" table="CLASSA">
<id type="string" unsaved-value="null" access="field">
<column name="CLASSA_ID" sql-type="char(32)" not-null="true"/>
<generator class="uuid.hex"/>
</id>
<one-to-one name="classBinstance" class="ClassB" cascade="all" constrained="true"/>
</class>
<class name="ClassB" table="CLASSB">
<id name="id" type="long" unsaved-value="null" access="field">
<column name="CLASSB_ID" sql-type="number(10)" />
<generator class="assigned"/>
</id>
...
...
</class>
now when I tried
cb ClassB = new ClassB();
ca ClassA = new ClassA(cb); //sets the inner property
storage.save(ca);
If FAILED ON UPDATE CLASS B !!!!
I saw
Insert into ClassA......
Update ClassB (when it did not insert it there yet).....
Is that mapping is right ?
i did not understand if i should put the class="foreign" in generator and where.....
help ? anyone ????