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: How do I retrieve the number of rows updated?
PostPosted: Sat Mar 07, 2009 12:00 pm 
Newbie

Joined: Sat Mar 07, 2009 11:55 am
Posts: 2
Hibernate version:

2.0

After calling SaveOrUpdate on 50 items, 3 are updated correctly. How do I retrieve the number 3?


Top
 Profile  
 
 Post subject: Found it
PostPosted: Sat Mar 07, 2009 4:18 pm 
Newbie

Joined: Sat Mar 07, 2009 11:55 am
Posts: 2
Found a blog post detailing something similar

public class AuditInterceptor : EmptyInterceptor
{
public int UpdateCount { get; private set; }
public int CreateCount { get; private set; }
public int DeleteCount { get; private set; }
public int TotalCount { get { return UpdateCount + CreateCount + DeleteCount; } }

public override void OnDelete(object entity, object id, object[] state, string[] propertyNames, IType[] types)
{
DeleteCount++;
}

public override bool OnFlushDirty(object entity, object id, object[] currentState, object[] previousState, string[] propertyNames, IType[] types)
{
UpdateCount++;
//if (entity is IAuditable)
//{
// for (int i = 0; i < propertyNames.Length; i++)
// {
// if ("lastUpdateTimestamp".Equals(propertyNames[i]))
// {
// currentState[i] = new DateTime();
// return true;
// }
// }
//}
return false;
}

public override bool OnSave(object entity, object id, object[] state, string[] propertyNames, IType[] types)
{
CreateCount++;

//if (entity is IAuditable)
//{
// for (int i = 0; i < propertyNames.Length; i++)
// {
// if ("createTimestamp".Equals(propertyNames[i]))
// {
// state[i] = new DateTime();
// return true;
// }
// }
//}
return false;
}

public override void AfterTransactionCompletion(ITransaction tx)
{
//if (tx.WasCommitted)
// Console.Write("Committed: ");
//else
// Console.Write("Rolled back: ");

//Console.WriteLine(" Creations: " + creates + ", Updates: " + updates + ", Deletes: " + deletes);
//updates = creates = deletes = 0;
}

}


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.