-->
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.  [ 12 posts ] 
Author Message
 Post subject: NHibernate VS 2005
PostPosted: Sun Mar 09, 2008 6:45 pm 
Newbie

Joined: Sun Mar 09, 2008 6:40 pm
Posts: 6
Guys is there a tutorial out there for NHibernate for 2005. App_Code is my assembly, however the below code bugs out with the following error

Unknown entity class: Authors

Code:

  Dim cfg As Configuration = New Configuration
        cfg.AddAssembly("App_Code")
        Dim factory As ISessionFactory = cfg.BuildSessionFactory
        Dim session As ISession
        session = factory.OpenSession
        Dim transaction As ITransaction
        transaction = session.BeginTransaction
        Dim objAuthor As New Authors
        objAuthor.AuthorEmail = "paul@test.com"
        objAuthor.AuthorName = "NHiver"
        objAuthor.AuthorNotify = True
        objAuthor.AuthorPassword = "Nhibernate"
        objAuthor.IsAuthorAdmin = True

        session.Save(objAuthor)
        transaction.Commit()
        session.Close()

'-----------------------------------------------------------------
Mapping file is stored in App_Globalresources is this correct? Or what directory should it be in? bin directory?
'------------------------------------------------------------------

Mapping directory - no idea how to set it as an embedded resource, cant find this option in VS 2005, perhaps this is a VS 2003 option only. Right clicking on the xML file in solution explorer just gives two properties in the property pane, filename and file location.
'----------------------------------------------------------------------

'------------------------------------------------------------------------------

Code:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
    <class name="Authors" table="tbl_authors">
   <id name="Id" column="fld_author_id" type="Int">
            <generator class="identity" />
        </id>
        <property name="AuthorName" column="fld_author_name" type="String" length="40"/>
   <property name="IsAuthorAdmin" column="fld_author_admin" type="Boolean" />
   <property name="AuthorUserName" column="fld_author_user" type="String" length="40"/>
   <property name="AuthorEmail" column="fld_author_email" type="String" length="40"/>
   <property name="AuthorPassword" column="fld_author_pass" type="String" length="40"/>
   <property name="AuthorNotify" column="fld_author_notify" type="Boolean"/>
    </class>
</hibernate-mapping>


Many thanks in advance for any tips tricks for VS 2005.


Top
 Profile  
 
 Post subject: Re: NHibernate VS 2005
PostPosted: Mon Mar 10, 2008 12:20 pm 
Newbie

Joined: Tue Feb 26, 2008 10:42 am
Posts: 5
Location: England
paulanthony22 wrote:
Code:
<class name="Authors" table="tbl_authors">



try this instead...

Code:
<class name="App_Code.Authors, App_Code" table="tbl_authors">


Maybe that works?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 10, 2008 1:09 pm 
Regular
Regular

Joined: Wed Jan 25, 2006 1:11 am
Posts: 118
Location: Copenhagen, Denmark
When you are calling AddAssembly nHibernate looks for embedded ressources in this assembly who have the extension hbm.xml. I don't think you can embed ressources in App_Code's assembly wh (which i assume have a generic name and not just App_Code)

App_ClobalResources is used for ressourcefiles.

Read the getting started in the nHibernate reference manual on how to create an nHibernate project and Embed mappingfiles as ressources in you assembly. Outside your webproject which in my opionion is better design.

Or if you insist on having them in App_Code use for instance AddFile on configuration instead of AddAssembly and specify a path to your mappingfile.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 12, 2008 3:54 pm 
Newbie

Joined: Sun Mar 09, 2008 6:40 pm
Posts: 6
Is this the reference you mean?

http://www.hibernate.org/362.html

There doesn't appear to be any VS 2005 references within this, all 2003 related steps.

cfg.AddFile(Server.MapPath("App_Code/Authors.hbm.xml"))


I now get the following error...


Could not load type 'App_Code.Authors' from assembly 'App_Code.cf7g_box, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.


note the cf7g_box extension changes upon recompile..Any further advice, much appreciated guys.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 12, 2008 4:04 pm 
Regular
Regular

Joined: Wed Jan 25, 2006 1:11 am
Posts: 118
Location: Copenhagen, Denmark
Im not the guy to speak to about App_Code and nHibernate, as i thinks its a weird concept having business entities in your web project, so let me ask you: Why do you want to have your classes in App_Code folder? I would strongly advice you to put them in a seperate project in the same solution.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 12, 2008 5:12 pm 
Newbie

Joined: Sun Mar 09, 2008 6:40 pm
Posts: 6
Its not a matter of want..

Its a matter of not knowing any better.

Thanks for the suggestion, I'll give that a shot.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 12, 2008 5:28 pm 
Newbie

Joined: Sun Mar 09, 2008 6:40 pm
Posts: 6
Code:
        Dim cfg As Configuration = New Configuration
        ' Response.Write()
        'Response.End()
        'cfg.Configure(Server.MapPath("bin/Hibernate.cfg.xml"))
        cfg.Configure()


        'cfg.AddAssembly("NewsmanagerDLL")


        cfg.AddFile(Server.MapPath("Bin/NewsmanagerDLL.Authors.hbm.xml"))
        'cfg.AddAssembly(.GetName.Name)


        Dim factory As ISessionFactory = cfg.BuildSessionFactory
        Dim session As ISession
        session = factory.OpenSession
        Dim transaction As ITransaction
        transaction = session.BeginTransaction
        Dim objAuthor As New Authors
        objAuthor.AuthorEmail = "paul@rw.com"
        objAuthor.AuthorName = "NHiver"
        objAuthor.AuthorNotify = True
        objAuthor.AuthorPassword = "Nhibernate"
        objAuthor.IsAuthorAdmin = True

        session.Save(objAuthor)
        transaction.Commit()
        session.Close()


I now get a different error

Line 48: cfg.AddFile(Server.MapPath("Bin/NewsmanagerDLL.Authors.hbm.xml"))

Could not load type NewsmanagerDLL.Authors. Possible cause: no assembly name specified.

Thanks for your help so far.[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 13, 2008 3:12 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
If you flag your mapping file as "Embedded Resource", you don't have to add it explicitly. Hibernate parses the assembly.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 13, 2008 3:50 am 
Newbie

Joined: Sun Mar 09, 2008 6:40 pm
Posts: 6
http://blog.webdistortion.com/2008/03/13/nhibernate-another-guide-for-visual-studio-2005/

I still dont know how to explicitly embed resources in my assembly. I've documented the process of how I got it to work at the above website. Thanks for the help guys, no doubt I'll be sticking around here with other questions.

Regards,
Paul


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 13, 2008 5:10 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
You have to include the hbm.xml in your project. Then you get the advanced properties like "Embedded Resource".

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Use WAP project
PostPosted: Mon Mar 17, 2008 10:33 pm 
Newbie

Joined: Thu Oct 18, 2007 10:30 am
Posts: 2
You can set the 'Embedded Resource' property, only if you select a Web Application Project - project type for your website.

With 2005, the WAP option comes with SP1, and is probably also available as a separate download.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 18, 2008 4:31 am 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
Use two projects.

Your first project should be an Assembly project which can contain your domain objects an mapping files. In this project you should be able to select a mapping file and the properties dialog should allow you to change the file to an Embedded Resource.

Your second project can be a web project and you can then reference your first project from it. In this project your configuration can be set up to automatically use the mappings from your other project by using the <mapping assembly="your_first_project" /> tag in the <session-factory> node where your_first_project refers to the project I'm talking about in my last paragraph.

Symon.

_________________
Symon Rottem
http://blog.symbiotic-development.com


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