-->
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: Can not save empty string in Oracle
PostPosted: Fri Jun 17, 2005 7:34 am 
When I try to save object with empty string field, appears this exception,
but when string value is null, it works correctly.

Quote:
Unhandled Exception: NHibernate.ADOException: could not synchronize database state with session ---> System.Exception: Parameter ':p19': No size set for variable length data type: String.
at System.Data.OracleClient.OracleParameterBinding.PrepareForBind(OracleConnection connection, Int32& offset)
at System.Data.OracleClient.OracleCommand.Execute(OciHandle statementHandle, CommandBehavior behavior, Boolean isReader, Boolean needRowid, OciHandle& rowidDescriptor, ArrayList& refCursorParameterOrdinals)
at System.Data.OracleClient.OracleCommand.Execute(OciHandle statementHandle, CommandBehavior behavior, Boolean needRowid, OciHandle& rowidDescriptor)
at System.Data.OracleClient.OracleCommand.ExecuteNonQueryInternal(Boolean needRowid, OciHandle& rowidDescriptor)
at System.Data.OracleClient.OracleCommand.ExecuteNonQuery()
at NHibernate.Impl.BatcherImpl.ExecuteNonQuery(IDbCommand cmd)
at NHibernate.Impl.NonBatchingBatcher.AddToBatch(Int32 expectedRowCount)
at NHibernate.Persister.EntityPersister.Update(Object id, Object[] fields, Boolean[] includeProperty, Object oldVersion, Object obj, SqlString sqlUpdateString, ISessionImplementor session)
at NHibernate.Persister.EntityPersister.Update(Object id, Object[] fields, Int32[] dirtyFields, Object[] oldFields, Object oldVersion, Object obj, ISessionImplementor session)
at NHibernate.Impl.ScheduledUpdate.Execute()
at NHibernate.Impl.SessionImpl.ExecuteAll(IList list)
at NHibernate.Impl.SessionImpl.Execute()
--- End of inner exception stack trace ---
at NHibernate.Impl.SessionImpl.Execute()
at NHibernate.Impl.SessionImpl.Flush()


Thanks for your help,
Serega


Top
  
 
 Post subject:
PostPosted: Sat Jun 18, 2005 11:26 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
Can you post your mapping files (hbm.xml) ?

And look at the generated SQL to know which parameter is ':p19'.

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 18, 2005 11:43 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
This is a known bug because Oracle does some strange things with null/empty strings. We don't have Oracle installed (yet), so we can't fix it, but I will integrate a fix if one is proposed.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 05, 2005 6:15 am 
Beginner
Beginner

Joined: Sun Jun 19, 2005 2:21 pm
Posts: 21
It is a bug in OracleClient provider and occurs only when inserting/updating an empty string in a varchar column.

Since I have the same problem as you, I would like to propose NHibernate developers to integrate a workaround into NHibernate source to check:
    - if the destination db is Oracle,
    - the column to be updated is of type varchar or alike
    - and the value to insert is empty string.

If all these conditions evaluate to true, update parameter value before sending to Oracle provider with DBNull.Value.


Top
 Profile  
 
 Post subject: problem
PostPosted: Wed Jul 06, 2005 10:08 am 
This problem is more annoying than it may seem, because I can not always check fields manually before saving/updating and it cause exceptions.


Top
  
 
 Post subject: JIRA
PostPosted: Wed Jul 06, 2005 6:37 pm 
I believe there's already an issue open for this: http://jira.nhibernate.org/browse/NH-162

The fix posted in this issue sets the size of the parameter string which makes Oracle happy.

Mike


Top
  
 
 Post subject:
PostPosted: Fri Jul 08, 2005 10:55 am 
Thanks! It really works but after small correction


Top
  
 
 Post subject: My fix
PostPosted: Wed Jul 13, 2005 4:45 pm 
Beginner
Beginner

Joined: Wed Jun 01, 2005 3:22 pm
Posts: 38
Location: Menlo Park, CA
I used an Interceptor.

Code:
      public static bool EmptyStringToNull(object[] state, NHibernate.Type.IType[] types)
      {
         bool modified = false;
         for (int i = 0; i < types.Length; i++)
         {
            if ( (types[i] is NHibernate.Type.AnsiStringType || state[i] is string)
               && state[i] != null
               && state[i].ToString() == "")
            {
               state[i] = null;
               modified = true;
            }
         }
         return modified;
      }

Code:
      public bool OnFlushDirty(object entity, object id, object[] currentState, object[] previousState, string[] propertyNames, NHibernate.Type.IType[] types)
      {
         bool modified = EmptyStringToNull(currentState, types);
         return modified;
      }

      public bool OnSave(object entity, object id, object[] state, string[] propertyNames, NHibernate.Type.IType[] types)
      {
         bool modified = EmptyStringToNull(state, types);
         return modified;
      }


I made this to work with Oracle8i specifically, so you may want to adjust the IF statement to test for more than AnsiString.


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.