﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Ayende Rahien commented on NHibernate and Generic Entities</title><description>The file name should be User.hbm.xml, and it should be an embedded resource
</description><link>http://ayende.com/2951/nhibernate-and-generic-entities#comment8</link><guid>http://ayende.com/2951/nhibernate-and-generic-entities#comment8</guid><pubDate>Fri, 16 Nov 2007 05:02:39 GMT</pubDate></item><item><title>zahra karimi commented on NHibernate and Generic Entities</title><description> have build this example and it works until the session.Save(newUser) 
  
when an exception occures. 
  
  
NHibernate.MappingException "Unknown Entry Class: User"
  
  
Code:
  
            Configuration cfg = new Configuration();
  
            cfg.AddAssembly("nhibernate");
  
  
            ISessionFactory factory = cfg.BuildSessionFactory();
  
            ISession session = factory.OpenSession();
  
            ITransaction transaction = session.BeginTransaction();
  
  
            User newUser = new User();
  
            newUser.Id = "joe_cool";
  
            newUser.UserName = "Joseph Cool";
  
            newUser.Password = "abc123";
  
            newUser.EmailAddress = "joe (at) cool (dot) com";
  
            newUser.LastLogon = DateTime.Now;
  
  
            session.Save(newUser);
  
            transaction.Commit();
  
            session.Close();
  
  
User.cs
  
using System;
  
  
public class User
  
{
  
    private string id;
  
    private string userName;
  
    private string password;
  
    private string emailAddress;
  
    private DateTime lastLogon;
  
  
    public User()
  
    {
  
    }
  
  
    public string Id
  
    {
  
        get { return id; }
  
        set { id = value; }
  
    }
  
  
    public string UserName
  
    {
  
        get { return userName; }
  
        set { userName = value; }
  
    }
  
  
    public string Password
  
    {
  
        get { return password; }
  
        set { password = value; }
  
    }
  
  
    public string EmailAddress
  
    {
  
        get { return emailAddress; }
  
        set { emailAddress = value; }
  
    }
  
  
    public DateTime LastLogon
  
    {
  
        get { return lastLogon; }
  
        set { lastLogon = value; }
  
    }
  
}
  
  
User.hbm.xls
  
&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  
&lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.0"&gt;
  
  &lt;class name="User" table="users"&gt;
  
    &lt;id name="Id" column="LogonId" type="String" length="20"&gt;
  
      &lt;generator class="assigned" /&gt;
  
    &lt;/id&gt;
  
    &lt;property name="UserName" column="Name" type="String" length="40"/&gt;
  
    &lt;property name="Password" type="String" length="20"/&gt;
  
    &lt;property name="EmailAddress" type="String" length="40"/&gt;
  
    &lt;property name="LastLogon" type="DateTime"/&gt;
  
  &lt;/class&gt;
  
&lt;/hibernate-mapping&gt;
  
  
if anyone can assist me, it would be greatly apreciated
  
  
</description><link>http://ayende.com/2951/nhibernate-and-generic-entities#comment7</link><guid>http://ayende.com/2951/nhibernate-and-generic-entities#comment7</guid><pubDate>Fri, 16 Nov 2007 04:56:39 GMT</pubDate></item><item><title>Ayende Rahien commented on NHibernate and Generic Entities</title><description>Visual Studio Class Diagrams
</description><link>http://ayende.com/2951/nhibernate-and-generic-entities#comment6</link><guid>http://ayende.com/2951/nhibernate-and-generic-entities#comment6</guid><pubDate>Thu, 15 Nov 2007 01:13:51 GMT</pubDate></item><item><title>Alan Buck commented on NHibernate and Generic Entities</title><description>This is just an inquiry. I have admired your UML? diagrams and wonder what you are using to produce them. I would like to use the same tool myself.
</description><link>http://ayende.com/2951/nhibernate-and-generic-entities#comment5</link><guid>http://ayende.com/2951/nhibernate-and-generic-entities#comment5</guid><pubDate>Thu, 15 Nov 2007 01:10:10 GMT</pubDate></item><item><title>Colin Jack commented on NHibernate and Generic Entities</title><description>I agree with you about generics and I wasn't pushing for a mass adoption of generics in the domain. However as Gary says using them in the domain can sometimes be useful. 
  
  
As you say having a generic contact information class is probably not what you want. However for something like a Range or another class in that mould having to create subclasses is a little bit nasty. Another example I can think of is where T is going to be one of more thanenum, though I'm not sure if we've ever met that case.
  
  
I'm all for expressing intent in my designs but we've definitely found a few cases where in order to just get something mapped we've had to create the non-generic subclasses despite the fact that we don't believe they've improved the design at all. 
  
  
So in actual fact these non-generic subclasses (which in one case I believe aren't even exposed outside the domain) are just adding the to the conceptual burden of understanding the domain.
  
  
Anyway ta for the response, as always it was very useful.
</description><link>http://ayende.com/2951/nhibernate-and-generic-entities#comment4</link><guid>http://ayende.com/2951/nhibernate-and-generic-entities#comment4</guid><pubDate>Wed, 14 Nov 2007 08:33:25 GMT</pubDate></item><item><title>Fabio Maulo commented on NHibernate and Generic Entities</title><description>When entity-name feature will be ported, probably, will be more easy to query generic entities too
  
(ref to http://www.hibernate.org/hib_docs/reference/en/html/mapping.html
  
 5.1.3)
  
  
Another possible use of generics entities is the use of &lt;any&gt; mapping (with all it implies).
  
  
I'm not secure but I think that, in the feature, we can think some solution and possible application of generics-entities, with a possible implementation, using special tuplizers (ref http://www.hibernate.org/hib_docs/reference/en/html/persistent-classes.html#persistent-classes-dynamicmodels)
</description><link>http://ayende.com/2951/nhibernate-and-generic-entities#comment3</link><guid>http://ayende.com/2951/nhibernate-and-generic-entities#comment3</guid><pubDate>Wed, 14 Nov 2007 06:40:37 GMT</pubDate></item><item><title>Sean Chambers commented on NHibernate and Generic Entities</title><description>I would personally think this would be handy to do, but would not do it myself.
  
  
The reason being is, by simply looking at the digram above it doesn't convey the meaning that well.
  
  
As you state it is possible to do this mapping with nhibernate which is great and I'm sure over a long enough time I could find a use for it, but unless I was sure that doing it this way would give me a huge benefit it would make me feel dirty.
  
  
Generics are very useful but I think people tend to go overboard with them trying to use them in instances where it's not warranted
</description><link>http://ayende.com/2951/nhibernate-and-generic-entities#comment2</link><guid>http://ayende.com/2951/nhibernate-and-generic-entities#comment2</guid><pubDate>Wed, 14 Nov 2007 03:18:54 GMT</pubDate></item><item><title>Gary commented on NHibernate and Generic Entities</title><description>Thanks for the tidbit!
  
  
Whilst generics aren't something I'd put throughout the domain layer there are times that I would do it, for instance (and these are probably the only 2 times that I would have done this):
  
  
- A generic Range value object (public class Range&lt;T&gt; where T : IComaprable&lt;T&gt;{})... robably mapped as a component in NHibernate.
  
- And a genric TemporalProperty association object (see http://martinfowler.com/eaaDev/TemporalProperty.html) where I want to hide the fact from the consumer that I am utilising a collection internally)
  
  
So in response to your request for a show of hands... I'll put one hand up and the other one down :-)
</description><link>http://ayende.com/2951/nhibernate-and-generic-entities#comment1</link><guid>http://ayende.com/2951/nhibernate-and-generic-entities#comment1</guid><pubDate>Wed, 14 Nov 2007 01:29:14 GMT</pubDate></item></channel></rss>