-->
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.  [ 5 posts ] 
Author Message
 Post subject: Problem with Generic
PostPosted: Thu Feb 08, 2007 5:42 am 
Newbie

Joined: Tue Jan 23, 2007 7:51 am
Posts: 2
Hi all, I have a problem with generics, and I'm not sure if this scenario it is possible.

I have a class that represent my primary keys (PrimaryKey<T>) and I don't know how write it in the hbm file.

I have been looking for info and samples but I haven't found nothing.

Fragment code:

namespace MyNHibernateSample
{
public class MyEntity
{
private PrimaryKey<string> id_1;
private PrimaryKey<int?> id_2;

public PrimaryKey<string> Id_1
{....}

public PrimaryKey<int?> Id_2
{....}
}
}

namespace MyNHibernateSample
{
public class PrimaryKey<T>
{
private T oldKey;
private T mKey;

public PrimaryKey(T key)
{
this.mKey = key;
this.oldKey = key;
}

...........
}
}

Any help would be appreciated.

Best Regards.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 30, 2007 4:02 pm 
Newbie

Joined: Fri Mar 30, 2007 4:00 pm
Posts: 2
Any chance this has been solved ? Looking to do something similar...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 02, 2007 2:59 pm 
Regular
Regular

Joined: Tue Mar 15, 2005 12:38 pm
Posts: 73
Location: Bucharest
If I did understand what you want to do you could use the composite-id mapping with some kind of custom accesor (see default implementations or Ayende's generics accessor for NH 1.0).

If you can't find more info, I will try to give you more details tomorrow.

_________________
Dragos


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 02, 2007 3:37 pm 
Newbie

Joined: Fri Mar 30, 2007 4:00 pm
Posts: 2
To clarify a bit (based on recent findings) ...

I have several generic entity classes that look like (greatly simplified)...

public class Foo<T>
{
protected string m_id;
protected string m_name;
protected T m_value;
protected IList<T> m_values;
public Foo()
{
Random rand = new Random();
m_values = new List<T>();
for (int i = 0; i < 10; i++)
{
m_values.Add(default(T));
}
}

public Foo(string _name, T _value) : this()
{
m_name = _name;
m_value = _value;
}

public virtual IList<T> Values
{
get { return m_values; }
set { m_values = value; }
}

public virtual string Id
{
get { return m_id; }
set { m_id = value; }
}

public virtual string Name
{
get { return m_name; }
set { m_name = value; }
}

public virtual T Value
{
get { return m_value; }
set { m_value = value; }
}
}

and I am trying to create a correct mapping file. There seems to be conflicting opinions regarding the general support of generics in 1.2RC1 (which may be caused by the close ties to Hib). Either way, there are suggestions out there that specify adding either '1 or '1[System.Int32] to the class name definition in the hbm file.

Then to confirm, I found a unit test in the NHib src (NHibernate.Test.GenericTest.Overall) that seemed to further suggest that a class declaration of <class name="A`1[System.Int32]" table="A"> in the hbm file should do the trick (at least for cases when <T> = <int> -- baby steps :-) ...

That was until I saw this in the unit test ...

[Ignore( "Generic entities not supported" )]

So I am back to the beggining, wondering if there is support for generic classes or just for generic lists ?

Thanks in advance...

Jeff


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 03, 2007 2:17 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Currently only generic collections are supported. Generic entities are not.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.