Reputation: 1147
I am new in NHibernate and need help. I have two classes:
class Pop3
{
public virtual long Id { set; get; }
public virtual string HostName { set; get; }
public virtual int Port { set; get; }
public virtual bool UseSsl { set; get; }
}
class Email
{
public virtual long Id { set; get; }
public virtual string UserName { set; get; }
public virtual string Password { set; get; }
public virtual Pop3 Host { set; get; }
}
I need to map them to NHibernate (uses Sqlite). That is easy with Pop3 class
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="TestAsm"
namespace="TestAsm.Entity.Mail">
<class name="Pop3" table="pop3hosts">
<id name="Id">
<generator class="identity" />
</id>
<property name="HostName" />
<property name="Port" />
<property name="UseSsl" />
</class>
</hibernate-mapping>
But how can I map Email class contains Pop3 class as property? My be i need to set Pop3.Id in Host property? But I think it is wrong way.
Upvotes: 0
Views: 3131
Reputation: 123901
This mapping belongs to the most basic, typical and well documented, I would say
An example, where the Pop3
class is mapped with many-to-one
over the column Pop3Id
:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="TestAsm"
namespace="TestAsm.Entity.Mail">
<class name="Email" table="email_table">
<id name="Id" generator="identity" />
<property name="UserName" />
<property name="Password" />
<many-to-one name="Host" column="Pop3Id" class="Pop3 " />
</class>
</hibernate-mapping>
Please check the Chapter 21. Example: Parent/Child
Upvotes: 2