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: Unknown entity class !!!
PostPosted: Thu Aug 03, 2006 5:04 pm 
Newbie

Joined: Wed Jun 01, 2005 9:22 pm
Posts: 3
Hi, I´m new with NHIbernate....if anyone know the answer...

I open a webApplication an configured the files like this :

web.config

<!-- Add this element -->
<configSections>
<section
name="hibernate-configuration"
type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"
/>
</configSections>

<!-- Add this element -->
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.0">
<session-factory>
<property name="dialect">NHibernate.Dialect.MsSql2000Dialect</property>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.connection_string">Server=(local);initial catalog=valmir;Integrated Security=SSPI</property>
</session-factory>
</hibernate-configuration>

cliente.cs
public class Cliente
{
public Cliente()
{
}

private int idCliente;
public int getIdCliente()
{
return idCliente;
}
public void setICliente(int value)
{
idCliente = value;
}

private string descricaoCliente;
public string getDescricaoCliente()
{
return descricaoCliente;
}
public void setDescricaoCliente(string value)
{
descricaoCliente = value;
}
}

cliente.hbm.xml

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">

<class name="Cliente" table="Cliente">

<id name="idCliente" column="idCliente" type="Int32" length="4" unsaved-value="0">
</id>

<property name="descricaoCliente" column= "descricaoCliente" type="String" length="50"/>

</class>

</hibernate-mapping>

AND in the webform

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using NHibernate;
using NHibernate.Cfg;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//ISessionFactory s = new NHibernate.Cfg.Configuration().Configure().BuildSessionFactory();

ISession session = NHibernateHelper.GetCurrentSession();

ITransaction tx = session.BeginTransaction();

Cliente c = new Cliente();
c.setICliente(9999);
c.setDescricaoCliente("9999");

session.Save(c);

tx.Commit();
}
}


public sealed class NHibernateHelper
{
private const string CurrentSessionKey = "nhibernate.current_session";
private static readonly ISessionFactory sessionFactory;

static NHibernateHelper()
{
sessionFactory = new NHibernate.Cfg.Configuration().Configure().BuildSessionFactory();
}

public static ISession GetCurrentSession()
{
HttpContext context = HttpContext.Current;
ISession currentSession = context.Items[CurrentSessionKey] as ISession;

if (currentSession == null)
{
currentSession = sessionFactory.OpenSession();
context.Items[CurrentSessionKey] = currentSession;
}

return currentSession;
}

public static void CloseSession()
{
HttpContext context = HttpContext.Current;
ISession currentSession = context.Items[CurrentSessionKey] as ISession;

if (currentSession == null)
{
// No current session
return;
}

currentSession.Close();
context.Items.Remove(CurrentSessionKey);
}

public static void CloseSessionFactory()
{
if (sessionFactory != null)
{
sessionFactory.Close();
}
}
}

AND When I run GET THE MESSAGE Unknown entity class !!!



Can someone help me !!! Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 04, 2006 4:47 am 
Senior
Senior

Joined: Wed Jun 15, 2005 4:17 am
Posts: 156
no need to "shout" !!!

What version of .NET are you using?
- if you are using 1.1 check if the mapping files are "embedded Resources".
- if you are using 2.0 you can't embed them so: either build a separate class library project with your business objects, and then you can mark them as embeded resources, either use the new "Web Application Projects" template for Visual Studio 2005 - you have to download the template from Microsoft - this I think will allow you to embed resources - it implements the "old" ASP.NET 1.x web project model.

HTH,
radu


Top
 Profile  
 
 Post subject: Unknown entity class !!!
PostPosted: Fri Aug 04, 2006 5:05 pm 
Newbie

Joined: Wed Jun 01, 2005 9:22 pm
Posts: 3
Thank you very much Radu !!!

Now works.......


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.