table:
*************************************************
create table [dbo].[child] (
[cid] [varchar] (36) [pid] [varchar] (36) null ,
[childname] [varchar] (50) null
)
create table [dbo].[parent] (
[pid] [varchar] (36) not null ,
[parentname] [varchar] (50) null
) on [primary]
go
alter table [dbo].[child] add
constraint [pk_child] primary key clustered
(
[cid]
) on [primary]
go
hbm.xml
*************************************************
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Business.Data.Parent,Business.Data" table="Parent">
<id name="Pid" column="PID" type="String">
<generator class="uuid.hex" />
</id>
<property column="ParentName" type="String" name="ParentName" length="50" />
<bag name="Children" inverse="true" lazy="true" cascade="all">
<key column="PID" />
<one-to-many class="Business.Data.Child, Business.Data" />
</bag>
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Business.Data.Child,Business.Data" table="Child"
dynamic-insert="true"
dynamic-update="true">
<id name="Cid" column="CID" type="String">
<generator class="uuid.hex"/>
</id>
<many-to-one name="Pid" column="PID" class="Business.Data.Parent,Business.Data" />
<property column="ChildName" type="String" name="ChildName" length="50" />
</class>
</hibernate-mapping>
test code
*************************************************
[Test]
public void testPC()
{
Configuration cfg = new Configuration();
cfg.AddAssembly("Business.Data");
ISessionFactory factory = cfg.BuildSessionFactory();
ISession session = factory.OpenSession();
ITransaction transaction = session.BeginTransaction();
// *********** Create Object *********************
Parent p = new Parent();
p.ParentName = "Parent";
Child c = new Child();
c.ChildName = "Child";
c.Pid = p;
p.Children.Add(c);
session.Save(p);
// ***********************************************
transaction.Commit();
session.Close();
}
log.txt
*************************************************
I want to get two insert statements:
insert parent...
insert child...
but, I get the follow statements:
insert parent...
update child...
why? buy maybe?
|