-->
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: VS2008 NHibernate 1.2
PostPosted: Sun Aug 24, 2008 5:38 am 
Newbie

Joined: Sun Aug 24, 2008 5:14 am
Posts: 3
Location: New York, NY
I am using NHibernate 1.2 under Visual Studio 2008 (VS2008) Web Application which dumps all the App_Code files into App_Code assembly, i.e., there's no right click to embed file.

In my User.hbm.xml I've tried various permutations of setting namespace, assembly and classname teg values to various resolutions off App_Code.NHbernateHelpers.User. I've tried stepping through the source code and have yet to determine where/what causes the exception Unknown entity class: NHibernateHelpers.User

I have also tried the constructor
static NHibernateHelper()
{
Configuration cfg = new Configuration().Configure();
cfg.AddDirectory(new System.IO.DirectoryInfo(HttpContext.Current.Server.MapPath(@"~/App_Code/")));
sessionFactory = cfg.BuildSessionFactory();
}



The exception is throw at the session.Save(u); line here...
protected void Page_Load(object sender, EventArgs e)
{
ISession session = NHibernateHelper.GetCurrentSession();
ITransaction tx = session.BeginTransaction();
User u = new User();
u.Name = "Joe";
session.Save(u);
tx.Commit();
NHibernateHelper.CloseSession();
}


It seems as if the App_Code qualifier gets lost in the sauce. So much for a quick start.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 24, 2008 12:54 pm 
Regular
Regular

Joined: Mon Aug 29, 2005 3:07 pm
Posts: 77
Have you set the build action of your mapping file (hbm.xml) to embedded resource ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 25, 2008 2:00 am 
Regular
Regular

Joined: Tue Jul 29, 2008 3:30 am
Posts: 74
I've also had this probelm and I only found two solutions:

1. Use a old style Website-Project in VS. That will give you the possibility to name the assembly.
2. Create a library for your business objects and mappings.

I've chosen solution 2 because of the drawbacks old Website-Projects have.


Top
 Profile  
 
 Post subject: Build Action
PostPosted: Mon Aug 25, 2008 4:27 pm 
Newbie

Joined: Sun Aug 24, 2008 5:14 am
Posts: 3
Location: New York, NY
whoami wrote:
Have you set the build action of your mapping file (hbm.xml) to embedded resource ?


In a Web Project's App_Code there is no right-click "Properties" menu pick that yields a property sheet with a "Build Action" selector the way there is in a class library project. See next post.


Last edited by waltsully on Mon Aug 25, 2008 5:04 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: NHibernate 1.2 VS2008 net 2.0 Web App "Unknown entity c
PostPosted: Mon Aug 25, 2008 5:03 pm 
Newbie

Joined: Sun Aug 24, 2008 5:14 am
Posts: 3
Location: New York, NY
cremor wrote:
I've also had this probelm and I only found two solutions:

1. Use a old style Website-Project in VS. That will give you the possibility to name the assembly.
2. Create a library for your business objects and mappings.

I've chosen solution 2 because of the drawbacks old Website-Projects have.


Thanks! This was road to success. It also matched the paradigm I typically use for solution organization. A Web UI, classLibrary BO (Business Objects/Logic) project and another classLibrary DA (Data Access) project. I tried a couple of ways to organize and found that you can put the hbm mapping files by themselves in the DA project and point at them from web.cofig setting. For the hbm content itself you need to set the assembly and namespace attributes to point to the BO project assembly and all works well.

NOTE -- as whoami suggests, one does need to set the Build Action to Embedded Resource; to do so, with the *.hbm.xml file in a class library project, right-click on the file, select Properties and in the Advanced Section find the Build Action property listed with its drop-down selector.


Tested okay with NHibernate 2.0.0-GA too.

Code:
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
      <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
      <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>         
         <property name="connection.connection_string">server=localhost; database=db1; Integrated Security=SSPI;</property>
      <mapping assembly="NHibernateSandBox.DA" />
    </session-factory>
</hibernate-configuration>


Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernateSandBox.BO" namespace="NHibernateSandBox.BO" >
    <class name="User" table="Users">   
      <!-- A 32 hex character is our surrogate key. It's automatically generated by NHibernate with the UUID pattern. -->
      <id name="Id">
        <column name="id" sql-type="nchar(32)" not-null="true"/>
        <generator class="uuid.hex" />
      </id>

      <property name="Name" column="name" type="string" />
     </class>
  </hibernate-mapping>


Code:
namespace NHibernateSandBox.BO
{
    public class User
    {
        private string id;
        private string name;

        public User()
        {
            //  constructor
        }
        public virtual string Id
        {
            get { return id; }
            set { id = value; }
        }
        public virtual string Name
        {
            get { return name; }
            set { name = value; }
        }
    }
}
[/i]


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.