-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: one-to-many problem
PostPosted: Fri Sep 22, 2006 3:23 am 
Newbie

Joined: Fri Sep 22, 2006 3:04 am
Posts: 5
here is the language table:
create table Multilinguals(id uniqueidentifier,languageCode varchar(10),nvarchar(max) content)
so any fields want to be multilingual just set it's sq-type to uniqueidentifier refer to Multilinguals.id
here is the Role table with name field to be multilingual:
create table Roles(id uniqueidentifier,name uniqueidentifier)
and following is the classes and hbm:
namespace DomainModel
{
public class Multilingual
{
private Guid _id;

public virtual Guid Id
{
get { return _id; }
set { _id = value; }
}
private string _languageCode;

public virtual string LanguageCode
{
get { return _languageCode; }
set { _languageCode = value; }
}
private string _content;

public virtual string Content
{
get { return _content; }
set { _content = value; }
}
public override bool Equals(object obj)
{
return base.Equals(obj);
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
}
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" assembly="DomainModel" namespace="DomainModel">
<class table="Multilinguals" name="Multilingual">
<composite-id>
<key-property name="Id" column="id"></key-property>
<key-property name="LanguageCode" column="languageCode"></key-property>
</composite-id>
<property name="Content" column="content"></property>
</class>
</hibernate-mapping>

using System;
using System.Collections.Generic;
using System.Text;
using Iesi.Collections;

namespace DomainModel
{
public class Role
{
private Guid _id;

public virtual Guid Id
{
get { return _id; }
set { _id = value; }
}

private ISet _names;

public virtual ISet Names
{
get { return _names; }
set { _names = value; }
}
}
}
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" assembly="DomainModel" namespace="DomainModel">
<class name="Role" table="Roles">
<id name="Id" column="id">
<generator class="assigned">
</generator>
</id>
<set name="Names">
<key column="id" foreign-key="name"></key>
<one-to-many class="Multilingual"/>
</set>
</class>
</hibernate-mapping>

and following is my test:
DomainModel.Role role= session.CreateCriteria(typeof(DomainModel.Role)).List<DomainModel.Role>()[0];
Console.WriteLine(role.Names.Count);
but it always output 0
what's the problem...help.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.