Hibernate Books

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: fill an object in constructor
PostPosted: Tue Jul 17, 2007 9:11 am 
Newbie

Joined: Mon Jul 16, 2007 3:19 am
Posts: 5
Hi,
I have a very simple question:
I have class Voter with ctor who supposed to get the object from DB.
The problom is that I did not succeded to fill the object 'this' itself because it's readonly. So what's i am doing now is fill another object (voterCopy) and then copy seperately field, field in 'copyValues' function.
How can I do it directly ?

public Voter()
{
NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
cfg.AddAssembly("LocalElectionsDll");
ISessionFactory factory = cfg.BuildSessionFactory();
ISession session = factory.OpenSession();
Voter voterCopy;
try
{
ITransaction transaction = session.BeginTransaction();
voterCopy = (Voter)session.Get(typeof(Voter), vPK);
transaction.Commit();
this.copyValues(voterCopy);
}
}
private void copyValues(Voter srcVoter)
{
this.sFirstName = srcVoter.sFirstName;
this.sLastName = srcVoter.sLastName;
. . .
}
}
Thanks !


Top
 Profile  
 
 Post subject: Re: fill an object in constructor
PostPosted: Mon Oct 31, 2011 10:06 am 
Newbie

Joined: Mon Oct 31, 2011 10:01 am
Posts: 1
-


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