If prepare_sql is true, columns of XML type won't work

Description

I am using SQL Server 2008.

I created a test case under NHibernate.Test, and added the line

<property name="prepare_sql">true</property>

to hibernate.cfg.xml.

The class to be persisted has one property of type XmlDocument: the automatic table creator creates a column of type xml and maps the property to it.

Saving a single element to the database gives this exception:

NHibernate.ADOException : While preparing INSERT INTO ClassWithXmlMember (Name, Xml) VALUES (@p0, @p1); select SCOPE_IDENTITY() an error occurred
----> System.InvalidOperationException : SqlCommand.Prepare method requires all variable length parameters to have an explicitly set non-zero Size.
at NHibernate.AdoNet.AbstractBatcher.Prepare(IDbCommand cmd) in AbstractBatcher.cs: line 119
at NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd) in AbstractBatcher.cs: line 216
at NHibernate.Id.IdentityGenerator.InsertSelectDelegate.ExecuteAndExtract(IDbCommand insert, ISessionImplementor session) in IdentityGenerator.cs: line 74
at NHibernate.Id.Insert.AbstractReturningDelegate.PerformInsert(SqlCommandInfo insertSQL, ISessionImplementor session, IBinder binder) in AbstractReturningDelegate.cs: line 42
at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object[] fields, Boolean[] notNull, SqlCommandInfo sql, Object obj, ISessionImplementor session) in AbstractEntityPersister.cs: line 2575
at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object[] fields, Object obj, ISessionImplementor session) in AbstractEntityPersister.cs: line 3035
at NHibernate.Action.EntityIdentityInsertAction.Execute() in EntityIdentityInsertAction.cs: line 75
at NHibernate.Engine.ActionQueue.Execute(IExecutable executable) in ActionQueue.cs: line 136
at NHibernate.Event.Default.AbstractSaveEventListener.PerformSaveOrReplicate(Object entity, EntityKey key, IEntityPersister persister, Boolean useIdentityColumn, Object anything, IEventSource source, Boolean requiresImmediateIdAccess) in AbstractSaveEventListener.cs: line 259
at NHibernate.Event.Default.AbstractSaveEventListener.PerformSave(Object entity, Object id, IEntityPersister persister, Boolean useIdentityColumn, Object anything, IEventSource source, Boolean requiresImmediateIdAccess) in AbstractSaveEventListener.cs: line 187
at NHibernate.Event.Default.AbstractSaveEventListener.SaveWithGeneratedId(Object entity, String entityName, Object anything, IEventSource source, Boolean requiresImmediateIdAccess) in AbstractSaveEventListener.cs: line 119
at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event) in DefaultSaveOrUpdateEventListener.cs: line 162
at NHibernate.Event.Default.DefaultSaveEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event) in DefaultSaveEventListener.cs: line 29
at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.EntityIsTransient(SaveOrUpdateEvent event) in DefaultSaveOrUpdateEventListener.cs: line 148
at NHibernate.Event.Default.DefaultSaveEventListener.PerformSaveOrUpdate(SaveOrUpdateEvent event) in DefaultSaveEventListener.cs: line 21
at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.OnSaveOrUpdate(SaveOrUpdateEvent event) in DefaultSaveOrUpdateEventListener.cs: line 53
at NHibernate.Impl.SessionImpl.FireSave(SaveOrUpdateEvent event) in SessionImpl.cs: line 2663
at NHibernate.Impl.SessionImpl.Save(Object obj) in SessionImpl.cs: line 485
at NHibernate.Test.XmlColumn.XmlColumnTest.FilteredQuery() in XmlColumnTest.cs: line 34
--InvalidOperationException
at System.Data.SqlClient.SqlParameter.Prepare(SqlCommand cmd)
at System.Data.SqlClient.SqlCommand.Prepare()
at NHibernate.Driver.DriverBase.PrepareCommand(IDbCommand command) in DriverBase.cs: line 281
at NHibernate.AdoNet.AbstractBatcher.Prepare(IDbCommand cmd) in AbstractBatcher.cs: line 113

Attached is the test code

Environment

None

Attachments

1

Activity

Show:

Alex Zaytsev May 1, 2017 at 3:42 AM

Closing issues resolved in 4.1.0

Alex Zaytsev December 11, 2015 at 8:17 AM

please review the pull request https://github.com/nhibernate/nhibernate-core/pull/449

Fabrizio Gennari August 22, 2013 at 5:21 PM

If prepare_sql is false, everything works correctly

Fixed

Details

Assignee

Reporter

Labels

Fix versions

Affects versions

Priority

Who's Looking?

Open Who's Looking?

Created August 22, 2013 at 5:20 PM
Updated May 1, 2017 at 3:42 AM
Resolved December 30, 2015 at 11:17 AM
Who's Looking?