-->
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.  [ 3 posts ] 
Author Message
 Post subject: Many to Many using Attributes
PostPosted: Thu Jul 26, 2007 7:08 am 
Newbie

Joined: Thu Jul 26, 2007 6:58 am
Posts: 19
Hi,

I am new to Hibernate and I am creating my first project using ORM tool.
The problem I have now is how to use many to many association.

I couldn't find examples in the internet. the ones I found use XML.

The code is that, but I don't know where to tell NHibernate to use the table Devices_DevicesGroup as associative table. I think it should be straight forward. (I don't and wouldn't like to have to device a class for the associative table as it works just as the LINK for the two real tables).

The tables involved are:

Devices
DevicesGroups
Devices_DevicesGroups (Only the PK for the two tables)

The code for Device DAO is

namespace DAO
{
[NHibernate.Mapping.Attributes.Class(Table = "devices")]
public class Device
{
private string _strImei;
private string _strDescription;
private string _strModel;
private string _strVersion;

//Many to Many relation
private List<DevicesGroup> _collDevicesGroups = null;

[NHibernate.Mapping.Attributes.Id(Name = "Imei")]
[NHibernate.Mapping.Attributes.Generator(1, Class = "assigned")]
public string Imei
{
get
{
return _strImei;
}
set
{
_strImei = value;
}
}

[NHibernate.Mapping.Attributes.Property(Column = "description")]
public string Description
{
get
{
return _strDescription;
}
set
{
_strDescription = value;
}
}

[NHibernate.Mapping.Attributes.Property(Column = "model")]
public string Model
{
get
{
return _strModel;
}
set
{
_strModel = value;
}
}

[NHibernate.Mapping.Attributes.Property(Column = "version")]
public string Version
{
get
{
return _strVersion;
}
set
{
_strVersion = value;
}
}

[NHibernate.Mapping.Attributes.ManyToMany(Class = "DevicesGroup", Column = "id")]
public List<DevicesGroup> DevicesGroups
{
get
{
return _collDevicesGroups;
}
set
{
_collDevicesGroups = value;
}
}

}
}


We are using NHibernate 1.0.3
Using only Attributes (without mapping files).
SQLServer Express 2005


Top
 Profile  
 
 Post subject: A good sample
PostPosted: Thu Jul 26, 2007 8:18 am 
Newbie

Joined: Wed May 23, 2007 4:09 am
Posts: 16
There is a good sample app here:
http://www.theserverside.net/tt/article ... NHibernate

It uses many to many relation. Just think that using nHibernate and attributes instead of hibernate and Xml mapping is nearly the same.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 26, 2007 9:15 am 
Newbie

Joined: Thu Jul 26, 2007 6:58 am
Posts: 19
Thanks, I've found the answer here:

http://forum.hibernate.org/viewtopic.ph ... attributes

Cheers


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

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.