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.  [ 10 posts ] 
Author Message
 Post subject: Working with multiple classes
PostPosted: Wed Apr 15, 2009 7:38 am 
Newbie

Joined: Mon Mar 30, 2009 2:47 pm
Posts: 15
hello! on my way to nhibernate i finished studying basic tutorial for introduction to it.Now i'm about to try a project with 3 tables/classes (let's not tald about mapping for now) currency| country | denomination.The challenge and what is confusing is the part of building a session.In fact i have a static function that return the session.
Code:
class NHibernateHelper
    {
        private static ISessionFactory _isessionFactory;

        private static ISessionFactory SessionFactory
        {
            get
            {
                if (_isessionFactory == null)
                {
                    Configuration cfg = new Configuration().Configure().AddAssembly(typeof(Currency).Assembly);
                    _isessionFactory = cfg.BuildSessionFactory();
                }
                return _isessionFactory;
            }
            set { _isessionFactory = value; }
        }


        public static ISession OpenSession()
        {
            return SessionFactory.OpenSession();
        }
    }


i've read on the documentation
Quote:
Another alternative (probably the best) way is to let NHibernate load all of the mapping files contained in an Assembly:
Configuration cfg = new Configuration()
.AddAssembly( "NHibernate.Auction" );

would that mean that i dont' have to add classes like Country and Denomination as in
Code:
Configuration cfg = new Configuration().Configure().AddAssembly(typeof(Currency).Assembly)
.AddAssembly(typeof(Country).Assembly)
.AddAssembly(typeof(Denomination).Assembly);

am i in the wrong path?thanks for reading this


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 15, 2009 10:52 am 
Newbie

Joined: Sun Apr 05, 2009 8:00 am
Posts: 8
As i understood your problem , the answer is Yes
but don't forget to add the assembly in the project assemblies


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 15, 2009 11:03 am 
Newbie

Joined: Sun Apr 05, 2009 8:00 am
Posts: 8
you can do that too:

Code:
ISessionFactory sessionFactory = new Configuration()
.Configure()
.AddXmlFile("Currency.hbm.xml")
.AddXmlFile("Country.hbm.xml")
.AddXmlFile("Denomination.hbm.xml")
.BuildSessionFactory();


the 3 ways are right u can choose the most suitable for u.


Last edited by Ahmed Emad on Thu Apr 16, 2009 3:32 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 15, 2009 11:31 am 
Newbie

Joined: Mon Mar 30, 2009 2:47 pm
Posts: 15
Common guys please point me to the right path.Please! Sorry that 's from my connection


Last edited by highjo on Wed Apr 15, 2009 11:55 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 15, 2009 11:34 am 
Newbie

Joined: Sun Apr 05, 2009 8:00 am
Posts: 8
doesn't my reply help?!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 15, 2009 11:58 am 
Newbie

Joined: Mon Mar 30, 2009 2:47 pm
Posts: 15
sorry i was desconnected.i did it and it works.I did try AddClass() :) thanks for the reply


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 15, 2009 12:11 pm 
Newbie

Joined: Mon Mar 30, 2009 2:47 pm
Posts: 15
actually something is wrong it's publishing the table alright but the unit testing can_add_country failed.

Also is there a simple way to have a thread safe session.I mean simple because i've read the sharp Architecture of Billy McCaferty and i didn't understand it.i guess for now it's too advanced for me.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 15, 2009 12:13 pm 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
I suggest you start some basic reading about nhibernate:

http://nhforge.org/wikis/howtonh/your-first-nhibernate-based-application.aspx

http://www.manning.com/kuate/

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 16, 2009 3:42 am 
Regular
Regular

Joined: Wed Feb 11, 2009 10:58 am
Posts: 55
Don't forget to set your hbm.xml files to embedded resource. Works like a charm for me :)

If you have got a Windows Forms Application and want to keep it simple just create one Session and use it throughout the whole program lifecycle (use a Singleton or something)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 16, 2009 4:09 am 
Newbie

Joined: Mon Mar 30, 2009 2:47 pm
Posts: 15
alright sounds interresting for me.will give a try and let you guys know.thanks


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