-->
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.  [ 8 posts ] 
Author Message
 Post subject: Problem in saving in DB
PostPosted: Thu Jun 21, 2007 1:11 pm 
Newbie

Joined: Tue May 15, 2007 4:38 am
Posts: 5
Hibernate version: 1.0.5000.0

Name and version of the database you are using: SQL Server 2005


My Problem is in this peace of code


The code in the Service

Code:

public void SaveArtifactsToTemplatesMapping(Hashtable artifactsFileStreams, string[] FileNames, Person aUserID, ProcessDefinition process)
        {
            // Authorize user can update attachment

            DataAccessManager dao = new DataAccessManager();
            try
            {
                // open transaction
                dao.BeginTransaction();

                // tell attachments manager to map artifacts to templates
                _attachmentManager.MapArtifactsToTemplates(artifactsFileStreams, FileNames, process);
                dao.FlushSession();

                dao.CommitTransaction();
            }
            catch (BusinessValidationException be)
            {
                dao.RollbackTransaction();
                throw be;
            }
            catch (Exception e)
            {
                dao.RollbackTransaction();
                throw new Exception("Exception in RenameeAttachment", e);
            }
            finally
            {
                if (dao.IsOpen)
                {
                    dao.Dispose();
                }
            }
           
        }


The code in the manager

Code:

_dao.UpdateAttachment(attachment);



the code in the Data access object

Code:

public void UpdateAttachment(AbstractAttachment anAttachment)
        {
            base.Save(anAttachment);
        }



the code in the base

Code:

public virtual void Save(Object BusinessObject)
{
try
{
   session.SaveOrUpdate(BusinessObject);
}
catch (Exception ex)
{
                // handle exception
                throw new DataAccessException(1402001, ex);
}
}



the Save action (or update) is not performed although there is not any errors or exceptions.

also, If i put this flush statement
Code:
_dao.FlushSession();
after the update command in the manager, it work correctly. but I don't want to do that because it's not logic and I want to know what is the logical solution.

I wait your advices.
Thank you for advance


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 21, 2007 1:50 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
There is no NHibernate version 1.0.5000.0.

The logical solution is to begin a transaction prior to calling SaveOrUpdate and commit it afterwards. The transaction management does not need to happen in the same method as SaveOrUpdate, of course.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 24, 2007 4:50 am 
Newbie

Joined: Tue May 15, 2007 4:38 am
Posts: 5
sergey wrote:
There is no NHibernate version 1.0.5000.0.

The logical solution is to begin a transaction prior to calling SaveOrUpdate and commit it afterwards. The transaction management does not need to happen in the same method as SaveOrUpdate, of course.


thank you for reply.

First, sorry the version is 0.84

Second, i already used the logic you talk about but the result is not correct.
as i said i don't want to use Flush command, but if i didn't, there was any update in the data base.

if there is a wrong logic in my code, please refer to it.

thx again.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 24, 2007 6:33 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
0.8.4 is a very old version, but this should work even in that version.

Since you don't provide any details on how you used transactions and what happened, it's hard to help you.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 24, 2007 8:54 am 
Newbie

Joined: Tue May 15, 2007 4:38 am
Posts: 5
sorry but i couldnt understand what do u mean with details of transaction ?

if u mean the beginning and commitiing the transaction, ok, i will explain it.

the beginning transaction is as the following peace of code
Code:
/// <summary>
///      Begin new Transaction
/// </summary>
public virtual void BeginTransaction()
{
   CheckSession();
   if (transaction == null)
{
                 transaction = session.BeginTransaction();
}
else
{
                throw new DataAccessException(1406001);
}
}


the "CheckSession" method is just to ensure that the session is connected

Code:
/// <summary>
///      Check current session if it Disconnected so reconnect it again.
/// </summary>
protected virtual void CheckSession()
{
   if(!session.IsConnected)
{
      session.Reconnect();
}
}


and the commiting is as the following

Code:
/// <summary>
///      Commit a transaction.
/// </summary>
public virtual void CommitTransaction()
{
   if (transaction != null)
   {
      transaction.Commit();
      transaction.Dispose();
      transaction = null;
   }
}


wait your feedback

Thank you for effort.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 01, 2007 4:18 am 
Newbie

Joined: Tue May 15, 2007 4:38 am
Posts: 5
No any feedback ? :(


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 01, 2007 4:39 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
So transaction.Commit should cause the SQL to be executed - is any SQL being executed when transaction.Commit is called?


Top
 Profile  
 
 Post subject: Any solution yet
PostPosted: Mon Jul 02, 2007 9:45 am 
Newbie

Joined: Mon Jul 02, 2007 8:27 am
Posts: 1
I am stuck with the same problem.. tried all things..Is there any solution?


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