-->
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.  [ 7 posts ] 
Author Message
 Post subject: Row was updated or deleted by another transaction
PostPosted: Fri May 16, 2008 6:52 am 
Newbie

Joined: Fri May 16, 2008 6:24 am
Posts: 4
He,

I have any problem to update persitent object, occurs when sending gazette to my subscribers.

While sendings email, someone subscriber can read to gazette. In this time, my persitent object contain diferents values.

How refresh object without loader other time?

Hibernate version: 1.2

Mapping documents:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-cascade="save-update">
 
  <class name="Cuyahoga.Modules.Newsletter.Domain.Campaign, Cuyahoga.Modules.Newsletter" table="cm_newsletter_campaign" lazy="true">
   
    <id name="Id" column="campaignid" type="Int32" unsaved-value="0">
      <generator class="native" />
    </id>
   
    <timestamp name="Updatetimestamp" column="updatetimestamp" unsaved-value="1/1/0001"  />
    <property name="Inserttimestamp" column="inserttimestamp" type="DateTime"  />
   
    <property name="Name" column="name" type="String" not-null="true" />
    <property name="Description" column="description" type="String" not-null="true" />
    <property name="Status" column="status" type="Int32" not-null="true" />
    <property name="FromName" column="fromname" type="String" not-null="true" />
    <property name="FromMail" column="frommail" type="String" not-null="true" />
    <property name="Subject" column="subject" type="String" not-null="true" />
    <property name="Body" column="body" type="String" not-null="true" />
    <property name="Valid" column="valid" type="Boolean" not-null="true" />
    <property name="GroupBelong" column="groupbelong" type="String" not-null="true" />
   
    <property name="TotalMails" column="totalmails" type="Int32" not-null="true" />
    <property name="SendMails" column="sendmails" type="Int32" not-null="true" />
    <property name="ReadMails" column="readmails" type="Int32" not-null="true" />
    <property name="Downs" column="downs" type="Int32" not-null="true" />
    <property name="Ups" column="ups" type="Int32" not-null="true" />
    <property name="Forwards" column="forwards" type="Int32" not-null="true" />
   
    <many-to-one name="CreatedBy"  class="Cuyahoga.Core.Domain.User, Cuyahoga.Core" column="createdby" />
    <many-to-one name="ModifiedBy"  class="Cuyahoga.Core.Domain.User, Cuyahoga.Core" column="modifiedby" cascade="save-update"  />
    <many-to-one name="Section"  class="Cuyahoga.Core.Domain.Section, Cuyahoga.Core" column="sectionid"/>
    <many-to-one name="Suscription"  class="Cuyahoga.Modules.Newsletter.Domain.Suscription, Cuyahoga.Modules.Newsletter" column="suscriptionid"/>
    <many-to-one name="Filter"  class="Cuyahoga.Modules.Newsletter.Domain.Filter, Cuyahoga.Modules.Newsletter" column="filterid" />
   
    <bag name="Queues" lazy="true" cascade="none">
       <key column="campaignid" />
       <one-to-many class="Cuyahoga.Modules.Newsletter.Domain.CampaignQueue, Cuyahoga.Modules.Newsletter" />
    </bag>

  </class>
 
</hibernate-mapping>


Full stack trace of any exception that occurs:

Code:
{"Row was updated or deleted by another transaction (or unsaved-value
mapping was incorrect) for Cuyahoga.Modules.Newsletter.Domain.Campaign instance with identifier: 585"}
    [NHibernate.StaleObjectStateException]: {"Row was updated or
deleted by another transaction (or unsaved-value mapping was
incorrect) for Cuyahoga.Modules.Newsletter.Domain.Campaign instance with identifier: 585"}
    Data: {System.Collections.ListDictionaryInternal}
    HelpLink: null
    InnerException: null
    Message: "Row was updated or deleted by another transaction (or
unsaved-value mapping was incorrect) for Cuyahoga.Modules.Newsletter.Domain.Campaign instance with
identifier: 585"
    Source: "NHibernate"
    StackTrace: "   en
NHibernate.Persister.Entity.AbstractEntityPersister.Check(Int32 rows,
Object id, Int32 tableNumber, IExpectation expectation, IDbCommand
statement)\r\n   en
NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object id,
Object[] fields, Object[] oldFields, Boolean[] includeProperty, Int32
j, Object oldVersion, Object obj, SqlCommandInfo sql,
ISessionImplementor session)\r\n   en
NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object id,
Object[] fields, Int32[] dirtyFields, Boolean hasDirtyCollection,
Object[] oldFields, Object oldVersion, Object obj, ISessionImplementor
session)\r\n   en NHibernate.Impl.ScheduledUpdate.Execute()\r\n   en
NHibernate.Impl.SessionImpl.Execute(IExecutable executable)\r\n   en
NHibernate.Impl.SessionImpl.ExecuteAll(IList list)\r\n   en
NHibernate.Impl.SessionImpl.Execute()\r\n   en
NHibernate.Impl.SessionImpl.Flush()\r\n   en
Castle.Facilities.NHibernateIntegration.SessionDelegate.Flush()\r\n
en Cuyahoga.Modules.Newsletter.DataAccess.CampaignDao.SaveCampaign(Campaign campaign)\r\n   en
ICampaignDaoProxy57f8a141904e41c080e30db4b0039abe.InvocationSaveCampaign_10.InvokeMethodOnTarget()
\r\n   en Castle.DynamicProxy.AbstractInvocation.Proceed()\r\n   en
Castle.Facilities.AutomaticTransactionManagement.TransactionInterceptor.Intercept(IInvocation
invocation)\r\n   en Castle.DynamicProxy.AbstractInvocation.Proceed()\r
\n   en
ICampaignDaoProxy57f8a141904e41c080e30db4b0039abe.SaveCampaign(Campaign
campaign)\r\n   en SaveCampaign(Campaign campaign)\r\n   en
Web.EditCampaign_send.DoWork(Object _context)"
    TargetSite: {Void Check(Int32, System.Object, Int32,
NHibernate.AdoNet.IExpectation, System.Data.IDbCommand)}


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 16, 2008 8:31 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
I'm not sure if that's what you're looking for. Yuo can refresh an object with

session.Refresh(obj);

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 16, 2008 9:06 am 
Newbie

Joined: Fri May 16, 2008 6:24 am
Posts: 4
I prove session.Refresh() but follow to problem.

This moment update the attribute ReadMails the principal process not pick up new values.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 16, 2008 9:53 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Can you post the code where you get the object and where you persist the object ?

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 19, 2008 3:28 am 
Newbie

Joined: Fri May 16, 2008 6:24 am
Posts: 4
Good morning and sorry for write a late.

Here to increments attribute SendMail:

Quote:
ISession session = this._sessionManager.OpenSession();
NHibernate.ITransaction tx = session.BeginTransaction();

try
{

/*Update the campaign information*/
string hql1 = "from Campaign as camp " +
"where camp.Id = :idcampaign ";
IQuery q1 = session.CreateQuery(hql1);
q1.SetParameter("idcampaign", campaignId);

Campaign currentCampaign = q1.UniqueResult<Campaign>();
currentCampaign.SendMails++;
session.Update(currentCampaign);
session.Flush();

/*Update the queue information*/
string hql2 = "from CampaignQueue as campq " +
"where campq.Id.Campaign.Id = :idcampaign " +
"and campq.Id.User.Id = :iduser ";
IQuery q2 = session.CreateQuery(hql2);
q2.SetParameter("idcampaign", campaignId);
q2.SetParameter("iduser", userId);

CampaignQueue currentQueue = q2.UniqueResult<CampaignQueue>();
currentQueue.StatusSend = true;

this._sessionManager.OpenSession().Update(currentQueue);
this._sessionManager.OpenSession().Flush(); //new

tx.Commit();

}
catch
{
tx.Rollback();
}
finally
{
tx.Dispose();
session.Close();
}


and here:

Quote:
if (_campaignDao.UpdateCampaignQueue(campaignId, userId))
{
Campaign campaign = _campaignDao.getCampaignId(campaignId);
campaign.ReadMails++;
_campaignDao.SaveCampaign(campaign);
}


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 19, 2008 4:27 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Some questions:

- You get the exception in campaignDao.SaveCampaign, right ?
- What does _campaignDao.getCampaignId do ?
- the code above is campaignDao.UpdateCampaignQueue(campaignId, userId) ?

Just some thoughts about the code, you object is loaded in this session, so you don't need to do an session.Update() on it. Just flush the session. Same with the current queue, there's no need to save it in a new session just try the following:

Code:
string hql1 = ...
IQuery q1 = ...

Campaign currentCampaign = q1.UniqueResult<Campaign>();
currentCampaign.SendMails++;

/*Update the queue information*/
string hql2 = ...
IQuery q2 = ...

CampaignQueue currentQueue = q2.UniqueResult<CampaignQueue>();
currentQueue.StatusSend = true;

session.Flush();

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 19, 2008 9:56 am 
Newbie

Joined: Fri May 16, 2008 6:24 am
Posts: 4
I seem whith find solution.

I resolve to problem having session.Refresh(campaign), before modified values to persistent object.

for the time being not visible problems, now I have test to correct operation


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