Hello there,
i'm having heavy trouble getting my ternary association to work. I
tryed the way which is shortly described in the nh-reference:
http://www.nhforge.org/doc/nh/en/index.html#collections-ternary
I set up the mapping for my classes like this (using
NHibernate.Mapping.Attributes):
Application.cs:
-------------------
[Class(0, Table = "APPLICATION")]
public class Application
{
private long id;
private string name;
private string assemblyGuid;
private IDictionary< AdGroup, Permission > groupPermissions =
new Dictionary< AdGroup, Permission >();
/// <summary>
/// Id der Anwendung
/// </summary>
[Id(0, TypeType = typeof(long), Column = "ID", Name = "Id",
UnsavedValue = "0")]
[Generator(1, Class = "native")]
[Param(2, Name = "sequence", Content = "APPLICATION_ID_SEQ")]
public virtual long Id
{
get
{
return this.id;
}
set
{
this.id = value;
}
}
/// <summary>
/// Assembly-Name der Anwendung
/// </summary>
[Property(0, Column = "NAME", Name = "Name", TypeType = typeof
(string), NotNull = true)]
public virtual string Name
{
get
{
return this.name;
}
set
{
this.name = value;
}
}
/// <summary>
/// Guid der Assembly
/// </summary>
[Property(0, Column = "ASSEMBLY_GUID", TypeType = typeof
(string), Name = "AssemblyGuid")]
public virtual string AssemblyGuid
{
get
{
return this.assemblyGuid;
}
set
{
this.assemblyGuid = value;
}
}
[Map(0, Table = "GROUP_APPLICATION_PERMISSION", Lazy = false,
Inverse = true, Cascade = "all")]
[Key(1, Column = "APPLICATION_ID")]
[IndexManyToMany(2, Column = "AD_GROUP_ID", ClassType = typeof
(AdGroup))]
[ManyToMany(3, ClassType = typeof(Permission), Column =
"PERMISSION_ID", Fetch = FetchMode.Join, Lazy =
RestrictedLaziness.False)]
public virtual IDictionary< AdGroup, Permission >
GroupPermissions
{
get { return this.groupPermissions; }
set { this.groupPermissions = value;}
}
}
AdGroup.cs
----------------
[Class(0, Table = "AD_GROUP")]
public class AdGroup
{
private long id;
private string samAccountName;
[Id(0, TypeType = typeof(long), Column = "ID", Name = "Id",
UnsavedValue = "0")]
[Generator(1, Class = "native")]
[Param(2, Name = "sequence", Content = "AD_GROUP_ID_SEQ")]
public virtual long Id
{
get
{
return this.id;
}
set
{
this.id = value;
}
}
[Property(0, TypeType = typeof(string), Unique = true, Column
= "SAM_ACCOUNT_NAME", Name = "SamAccountName")]
public virtual string SamAccountName
{
get
{
return this.samAccountName;
}
set
{
this.samAccountName = samAccountName;
}
}
}
Permission.cs:
--------------------
[Class(0, Table = "PERMISSION")]
public class Permission
{
private long id;
private string name;
private ISet< Application > applicationList = new HashedSet<
Application >();
[Id(0, TypeType = typeof(long), Column = "ID", Name = "Id",
UnsavedValue = "0")]
[Generator(1, Class = "native")]
[Param(2, Name = "sequence", Content = "PERMISSION_ID_SEQ")]
public virtual long Id
{
get
{
return this.id;
}
set
{
this.id = value;
}
}
[Property(0, Column = "NAME", TypeType = typeof(string),
Unique = true, Name = "Name", NotNull = true)]
public virtual string Name
{
get
{
return this.name;
}
set
{
this.name = value;
}
}
public virtual ISet<Application> ApplicationList
{
get { return this.applicationList; }
set{ this.applicationList = value;}
}
}
These are the resulting xml-mapping-files: (Class-Names and Namespaces
have been deleted or changed)
Application.hbm.xml:
--------------------------
<?xml version="1.0" encoding="utf-8"?>
<!--Generated by NHibernate.Mapping.Attributes on 2009-04-08
08:27:55Z.-->
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Application" table="APPLICATION">
<id name="Id" column="ID" type="Int64" unsaved-value="0">
<generator class="native">
<param name="sequence">APPLICATION_ID_SEQ</param>
</generator>
</id>
<property name="Name" type="String" column="NAME" not-null="true" /
>
<property name="AssemblyGuid" type="String"
column="ASSEMBLY_GUID" />
<map name="GroupPermissions" table="GROUP_APPLICATION_PERMISSION"
lazy="false" cascade="all" inverse="true">
<key column="APPLICATION_ID" />
<index-many-to-many class="AdGroup" column="AD_GROUP_ID" />
<many-to-many class="Permission" column="PERMISSION_ID"
fetch="join" lazy="false" />
</map>
</class>
</hibernate-mapping>
AdGroup.hbm.xml:
-----------------------
<?xml version="1.0" encoding="utf-8"?>
<!--Generated by NHibernate.Mapping.Attributes on 2009-04-08
08:27:55Z.-->
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="AdGroup" table="AD_GROUP">
<id name="Id" column="ID" type="Int64" unsaved-value="0">
<generator class="native">
<param name="sequence">AD_GROUP_ID_SEQ</param>
</generator>
</id>
<property name="SamAccountName" type="String"
column="SAM_ACCOUNT_NAME" unique="true" />
</class>
</hibernate-mapping>
Permission.hbm.xml:
--------------------------
<?xml version="1.0" encoding="utf-8"?>
<!--Generated by NHibernate.Mapping.Attributes on 2009-04-08
08:27:55Z.-->
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Permission" table="PERMISSION">
<id name="Id" column="ID" type="Int64" unsaved-value="0">
<generator class="native">
<param name="sequence">PERMISSION_ID_SEQ</param>
</generator>
</id>
<property name="Name" type="String" column="NAME" not-null="true"
unique="true" />
</class>
</hibernate-mapping>
This is how the tables are created using SchemaExport:
drop table if exists AD_GROUP
drop table if exists APPLICATION
drop table if exists GROUP_APPLICATION_PERMISSION
drop table if exists PERMISSION
create table AD_GROUP (ID integer, SAM_ACCOUNT_NAME TEXT unique,
primary key (ID))
create table APPLICATION (ID integer, NAME TEXT not null,
ASSEMBLY_GUID TEXT, primary key (ID))
create table GROUP_APPLICATION_PERMISSION (APPLICATION_ID INTEGER not
null, PERMISSION_ID INTEGER not null, AD_GROUP_ID INTEGER not null)
create table PERMISSION (ID integer, NAME TEXT not null unique,
primary key (ID))
So I hope I'll get some help here. Thanks for your support in advance!
Regards,
Maik
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---