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.  [ 6 posts ] 
Author Message
 Post subject: Win Forms Apps - Using NHibernate with Collections
PostPosted: Fri Jul 28, 2006 10:40 am 
Senior
Senior

Joined: Fri Jan 13, 2006 2:50 pm
Posts: 123
Location: Blumenau / SC / Brasil
Hi!

Is there anybody here using NHibernate with Collections bounded to the Interface controls?

And

How do you use NH with Win Forms Apps?

Thanks


Top
 Profile  
 
 Post subject: Re: Win Forms Apps - Using NHibernate with Collections
PostPosted: Fri Jul 28, 2006 5:25 pm 
Newbie

Joined: Sun Sep 25, 2005 9:11 am
Posts: 13
Location: Bergen, Norway
mdsrlz wrote:
Is there anybody here using NHibernate with Collections bounded to the Interface controls?


Check out http://forum.hibernate.org/viewtopic.php?t=961346

mdsrlz wrote:
How do you use NH with Win Forms Apps?


I have created an generic wrapper that implements most of the methods provided by ISession, and made this wrapper implement IComponent. For each entity I create a class inherited from the wrapper, and voila, I have strongly typed DAOs that easily can be used directly in a WinForm, and can be added using the designer.

For example:

Code:
public class GenericDao<T> : IComponent
{
    public virtual T Load(int id)
    {
        return (T)session.Load(typeof(T), id);
    }

    ...
}

public class CustomerDao : GenericDao<Customer>
{
}


And then:

Code:
Customer c = customerDao1.Load(123);


Each method in GenericDao<T> can be overridden, so if you want to add some business logic, you can easily add it for each entity.

I have also added some plumbing behind the scenes so a session can be shared across several DAOs, but the default feature is that each DAO gets its own session from the session factory.[/code]


Top
 Profile  
 
 Post subject: What about lazy initialization ??
PostPosted: Tue Aug 15, 2006 10:16 pm 
Beginner
Beginner

Joined: Wed Aug 09, 2006 10:15 am
Posts: 20
Location: Vitoria - ES - Brazil
I dont understand devolish ... Are you using lazy initialization ??

I use a very similar aproach that you are using except that I can't have have generics because we are still in .NET 1.1 .

The main difference is that I pass the current Sessao ( my wrapper class for session ) each time I need a DAO, just like that:

IPersonDAO personDAO = DAOFactory.GetDAOFactory().GetPersonDAO(sessao);

PS: sessao is an instance of Sessao.

Unhappilly even knowing this approach I've been facing a big challenge in making nHibernate work for winform applications.
And this is because of the way we manage sessions for winform applications is very different for web applications.

Solution we are testing here is to detach object from the Window session is attaching them to the Business logic session in order to prevent problems in case there is an exception.

Another interesting solution I found in this forum is to implement a LazyObjectCollection class. This class would bring objects from the database without the concern of having an open session.
Unhappilly I can't find the thread right now to point out.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 16, 2006 8:22 am 
Beginner
Beginner

Joined: Wed Mar 22, 2006 6:59 am
Posts: 30
Hi hcmarchezi and mdsrlz

i´m beginning my development using nhibernate, and i´m new to .NET too.
Could you, please, send more parts of the DAO layer you have implemented, please !!!!

I think this should be post in Nhibernate manual, as a "good practices" chapter.


Thanks for helping !


Top
 Profile  
 
 Post subject: Information abtou DAO and nHibernate
PostPosted: Fri Aug 18, 2006 7:34 am 
Beginner
Beginner

Joined: Wed Aug 09, 2006 10:15 am
Posts: 20
Location: Vitoria - ES - Brazil
pauloquicoli,

This is the nest article about nHibernate best practices I found including the DAO pattern.

http://www.codeproject.com/aspnet/NHibe ... ctices.asp


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 18, 2006 9:45 am 
Senior
Senior

Joined: Fri Jan 13, 2006 2:50 pm
Posts: 123
Location: Blumenau / SC / Brasil
Hi.

Ok, I have three projects here: DAL, DTO and BLL (i'm ignoring the interface for this moment).

DAL = Data Access Layer
DTO = Data Transfer Objects
BLL = Business Logic Layer

DTO and BLL use DTOs to receive/send data. In my DAL layer, I have a base class that implements a lot of usefull generic methods. Take a look:

Code:
namespace MyCompanyXXX.DAL
{
    public class BaseDAL
    {
        /// <summary>
        /// List all objects of type T using emp_id
        /// </summary>
        public static IList<T> List<T>()
        {
            return BaseDAL.List<T>(true);
        }

        /// <summary>
        /// List all objects of type T using or not emp_id field
        /// </summary>
        public static IList<T> List<T>(bool useEmpId)
        {
            string hql = "FROM " + typeof(T) + " AS obj";
            if (useEmpId)
                hql += " WHERE obj.EmpId = " + Infos.EmpId;

            IQuery query = NHHelper.Session.CreateQuery(hql);
            return query.List<T>();
        }

   ...


All my DAL classes inherits from BaseDAL :)

That is it!

Bye


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