Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:1.2.1
Mapping documents:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="NHibernate.Prototype.Domain"
assembly="NHibernate.Prototype"
default-access="field"
default-lazy="false"
default-cascade="none">
<class name="Foo" table="foo">
<id name="id">
<generator class="identity" />
</id>
</class>
</hibernate-mapping>
simple console app
Code:
Configuration configuration = new Configuration().Configure();
IFoo[] listOfFoos = new IFoo[] { new Foo(), new Foo(), new Foo() };
IFoo found;
using (ISessionFactory sessionFactory = configuration.BuildSessionFactory())
using (ISession session = sessionFactory.OpenSession())
{
using (ITransaction transaction = session.BeginTransaction())
{
foreach (IFoo foo in listOfFoos) session.Save(foo);
transaction.Commit();
}
found = session.Get<Foo>(2L);
}
foreach (IFoo foo in listOfFoos) Console.WriteLine("{2} {0} = 'found' {1}", foo.Id, foo == found, foo.GetType());
Console.ReadKey();
Full stack trace of any exception that occurs:"Unknown entity class: NHibernate.Prototype.Domain.IFoo"
" at NHibernate.Impl.SessionFactoryImpl.GetEntityPersister(Type theClass)\r\n at NHibernate.Impl.SessionImpl.GetClassPersister(Type theClass)\r\n at NHibernate.Impl.SessionImpl.DoLoadByClass(Type clazz, Object id, Boolean checkDeleted, Boolean allowProxyCreation)\r\n at NHibernate.Impl.SessionImpl.Get(Type clazz, Object id)\r\n at NHibernate.Impl.SessionImpl.Get[T](Object id)\r\n at NHibernate.Prototype.Program.Main() in C:\\JMeckley\\My Documents\\Visual Studio 2005\\Projects\\NHibernate.Prototype\\NHibernate.Prototype\\Program.cs:line 23\r\n at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)\r\n at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)\r\n at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()\r\n at System.Threading.ThreadHelper.ThreadStart_Context(Object state)\r\n at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)\r\n at System.Threading.ThreadHelper.ThreadStart()"
Name and version of the database you are using: .\SqlExpress
Debug level Hibernate log excerpt:0
I'm brand new to NH. Just started this week. after reading the docs, and various online blogs I wrote the simple console app above to begin to experimenting with the framework.
I want to program to interfaces, my mapping is for a class of Foo not the interface IFoo (1 id column) I can save new instances of IFoo without a problem. however when I fetch an IFoo the get the exception above stating it doesn't know how to fetch IFoo. If I change this to Get<Foo> everything works as expected.
here are the Foo objects:
Code:
namespace NHibernate.Prototype.Domain
{
public interface IFoo
{
long Id { get; }
}
public class Foo : IFoo
{
private long id;
public Foo()
{
}
public long Id
{
get { return id; }
}
public override string ToString()
{
return string.Format("Foo {0}", id);
}
}
}
is it possible to use Get<IFoo>(2L) without explicitly defining IFoo in an hbm? If not, can I do this without a descriminator column for the table? Am I way off base in what I'm attempting to do?
thank you
Jason