The
has two tables: User (user) and blog (set table), and the relationship between them is just as I said a one-to-one relationship. Now we map these two files:
<?xml version= "1.0" encoding= "Utf-8"?>
Now test how to save the data:
var userdal = new Userdal ();
var blogdal = new Blogdal ();
var user = new user{
name = name,
Password = Password,
posttitle = posttitle,
createtime = datetime.now,
avatar = FileUrl
};
var blog = new Blog {user = user};
User. blog = blog;
Blogdal.save (blog);
Userdal.save (user);
Summarize:
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/net/
This succeeded in saving data, made "Laozi" Day time, alas, in fact, hibernate one-to-one association with foreign Key Association, etc., I used this primary key association.
1: If the hibernate set
<id name= "id" >
<column name= "Id" sql-type= "varchar" not-null= "true"/>
<generator class= "Uuid.hex"/>
</id>
Such code, you can not use this code when adding data: Guid.NewGuid. (I didn't know it before, it was a failure).
2:
<generator class= "foreign" >
<param name= "Property" >User</param>
</generator>
This code means that the primary key of the blog refers to the primary key value in the user table.
3: That is, I saved the data, I am not sure if this operation, really a little self-confidence, if Bo friends have some hibernate experts, hope to come in to help me see, is not so save data (important), there are a pair is not such a configuration, alas, Hibernate me to vomit blood.