"Nevertheless, I can use OUTPUT parameters and I don't understand why they are not implemented in Hibernate yet. I ask developers, why???"
It's a fringe usage scenario, only relevant in legacy databases, where the developer can't modify the schema/procedures. NHibernate goes to great lengths to provide for legacy databases, but there are limits to what it can do, especially when it comes to stored procedures. Remember that NHibernate is not a data access library. Don't get me wrong. It's great that you have contributed, but "why???" is not a good way to market the contribution. /G 2013/4/28 <[email protected]> > So, today I've implemented it by myself. It tooks only 3 hours. > > What have I done: > 1. To "interface IBinder " (namespace NHibernate.Id.Insert) add one more > method: > void ExtractOutValues(IDbCommand cm); > 2. Implement that method in "private class GeneratedIdentifierBinder : > IBinder " (of "public abstract class AbstractEntityPersister ") (namespace > NHibernate.Persister.Entity > ) > > > public virtual void ExtractOutValues(IDbCommand ps) > { > entityPersister.ReDehydrate(entity, null, fields, notNull, > entityPersister.propertyColumnInsertable, 0, ps, session); > } > > > Where "ReDehydrate" is: > > protected int ReDehydrate(object entity, object id, object[] fields, bool[] > includeProperty, bool[][] includeColumns, int j, IDbCommand st, > ISessionImplementor session) > { > for (int i = 0; i < entityMetamodel.PropertySpan; i++) > { > if (includeProperty[i] && IsPropertyOfTable(i, j)) > { > try > { > this.SetPropertyValue(entity, i, > ((IDbDataParameter)st.Parameters[i]).Value, EntityMode.Poco); > } > catch (Exception ex) > { > throw new PropertyValueException("Error redehydrating > property value for", EntityName, entityMetamodel.PropertyNames[i], ex); > } > } > } > return 0; > } > > > > 4. And finally modify method "public object PerformInsert(SqlCommandInfo > insertSQL, ISessionImplementor session, IBinder binder)" > (public abstract class > AbstractReturningDelegate)(namespaceNHibernate.Id.Insert) > > after: > > IDbCommand insert = Prepare(insertSQL, session); > add: > > foreach (IDbDataParameter prm in insert.Parameters) > > { > > prm.Direction = ParameterDirection.InputOutput; > > > } > > > > > and change this: > > > binder.BindValues(insert); > > return ExecuteAndExtract(insert, session); > to this: > > object res; > binder.BindValues(insert); > > res = ExecuteAndExtract(insert, session); > > binder.ExtractOutValues(insert); > > return res; > > > 5. The End! > > It works and return my output parameters. > But after tran.Commit() operation it executes dynamically generated > "UPDATE" statement instead of my stored procedure. It thinks that it's > dirty. > For now, I don't know yet how to fix it. > Nevertheless, I can use OUTPUT parameters and I don't understand why they > are not implemented in Hibernate yet. > I ask developers, why??? > > > Понеділок, 22 квітня 2013 р. 22:08:42 UTC+3 користувач > [email protected]написав: >> >> I know nhibernate doesn't support output parameters? but I don't >> understand why. >> Why I can't write something like this: >> >> <class name="Document"> >> ... >> <sql-insert>exec createDocument ?,? OUT,?,?</sql-insert> >> ... >> </class> >> >> I think it's very easy to implement. >> >> Now, for data access code I'm using pure ADO.NET. And my "documents" >> table has "CreateDate" column, which is set by server, and returns to my >> application by output parameter of stored procedure. >> I know I can set "CreateDate" property of my POCO class manually but i >> don't want do it because I can't accurately synchronize client clock to the >> clock of server. >> > -- > You received this message because you are subscribed to the Google Groups > "nhusers" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/nhusers?hl=en-US. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- You received this message because you are subscribed to the Google Groups "nhusers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/nhusers?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
