-->
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.  [ 2 posts ] 
Author Message
 Post subject: nhibernate save my Object Automatically With out Use Save
PostPosted: Wed Feb 02, 2011 5:19 am 
Newbie

Joined: Mon Jan 31, 2011 4:49 am
Posts: 6
hi every body
i use nhibernate in my program and i use it to implement more than 14 classes
but i have this problem and i don't understand why nhibernate save objects to database

this is my code

Code:
ISession session = NHibernateHelper.GetCurrentSession();
                ITransaction tx = session.BeginTransaction();
                IQuery query = session.CreateQuery("select e from Employ as e");
                IList allEmploys = query.List();
                NHibernateHelper.CloseSession();
                   
                      //////get employs from database

                ((Library.Model_Classes.Employ)(allEmploys[0])).Fname = "www";
                ((Library.Model_Classes.Employ)(allEmploys[0])).Sname = "www";

                     ///////////update the first one

                session = NHibernateHelper.GetCurrentSession();
                tx = session.BeginTransaction();
                query = session.CreateQuery("select e from Employ as e");
                allEmploys = query.List();
                NHibernateHelper.CloseSession();


/// now i get allEmploys[0].Fname="www" in database and in allEmploys List
/// i don't save any thing but the nhibernate save my changes to database
i don't want to save any thing with out use (save,update,..........) operation

thank you very much for your help


Top
 Profile  
 
 Post subject: Re: nhibernate save my Object Automatically With out Use Save
PostPosted: Thu Feb 03, 2011 4:19 am 
Newbie

Joined: Mon Jan 31, 2011 4:49 am
Posts: 6
Hi every body

this solve my problem
Code:
//ISessionFactory _sessions;
                //_sessions = new Configuration().Configure().BuildSessionFactory();

                //IList allEmploys;
                //using (ISession session = _sessions.OpenSession())
                //using (ITransaction tx = session.BeginTransaction())
                //{
                //    IQuery query = session.CreateQuery("select e from Employ as e");
                //    allEmploys = query.List();
                //}

                //((Library.Model_Classes.Employ)(allEmploys[0])).Fname = "www";
                //((Library.Model_Classes.Employ)(allEmploys[0])).Sname = "www";

                //using (ISession session = _sessions.OpenSession())
                //using (ITransaction tx = session.BeginTransaction())
                //{
                //    IQuery query = session.CreateQuery("select e from Employ as e");
                //     allEmploys = query.List();
                //}


thx


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.