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.  [ 3 posts ] 
Author Message
 Post subject: Very Strange Error On Insert - Works locally but not live
PostPosted: Sat May 31, 2008 3:01 pm 
Newbie

Joined: Wed Feb 20, 2008 8:08 pm
Posts: 10
Hi,

I have developed an application locally and tested all functionality works as expected and everything does. When I deploy the application some funnies start happening such as an insert that worked locally stops working on the server (see error below). Locally I am developing against
full SQL Server 2005 but deployment works off SQL Express this is the only thing that I am aware of that may be causing an issue.

Any help is very much appreciated as I am stumped with this.

Thanks in advance,

Brendan

Please see the error message below:

-----------------------------------------------------------------------------------
Inner exception:
SqlException

Message:
Cannot insert the value NULL into column 'Id', table 'hughgrice.dbo.Painting'; column does not allow nulls. INSERT fails.
The statement has been terminated.

StackTrace:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
at NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd) in D:\@Repository\NHibernate\nhibernate\src\NHibernate\AdoNet\AbstractBatcher.cs:line 191
at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object[] fields, Boolean[] notNull, SqlCommandInfo sql, Object obj, ISessionImplementor session) in D:\@Repository\NHibernate\nhibernate\src\NHibernate\Persister\Entity\AbstractEntityPersister.cs:line 2301
--------------------------------------------------------------------------------

NHIBERNATE Web.Config ENTRY

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<!-- This is the System.Data.dll provider for MSSQL Server -->
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">
Server=(local);initial catalog=hughgrice;Integrated Security=SSPI
<!--Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\hughgrice.mdf;Integrated Security=True;User Instance=True-->
</property>
<property name="show_sql">True</property>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
<property name="use_outer_join">true</property>
<property name="command_timeout">444</property>
<property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
<property name="adonet.wrap_result_sets">False</property>
<property name="connection.release_mode">on_close</property>
</session-factory>
</hibernate-configuration>
--------------------------------------------------------------------------------
PAINTING HBM.XML

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false">
<class name="HughGRice.Portal.Core.Models.Painting, HughGRice.Portal.Core" table="Painting">
<id name="Id" type="Int32" unsaved-value="0">
<column name="Id" length="4" sql-type="int" not-null="true" unique="true" index="PK_Painting"/>
<generator class="native" />
</id>
<property name="Name" type="String">
<column name="Name" length="100" sql-type="nvarchar" not-null="true"/>
</property>
<property name="Description" type="String">
<column name="Description" length="200" sql-type="nvarchar" not-null="false"/>
</property>
<property name="Media" type="String">
<column name="Media" length="100" sql-type="nvarchar" not-null="false"/>
</property>
<property name="Size" type="String">
<column name="Size" length="20" sql-type="nvarchar" not-null="false"/>
</property>
<property name="Price" type="Decimal">
<column name="Price" length="8" sql-type="money" not-null="false"/>
</property>
<property name="Sold" type="Boolean">
<column name="Sold" length="1" sql-type="bit" not-null="false"/>
</property>
<property name="Photo" type="String">
<column name="Photo" length="50" sql-type="nvarchar" not-null="false"/>
</property>
<many-to-one name="Gallery" class="HughGRice.Portal.Core.Models.Gallery, HughGRice.Portal.Core">
<column name="GalleryId" length="4" sql-type="int" not-null="false"/>
</many-to-one>
<many-to-one name="PaintingType" class="HughGRice.Portal.Core.Models.PaintingType, HughGRice.Portal.Core">
<column name="PaintingTypeId" length="4" sql-type="int" not-null="false"/>
</many-to-one>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 02, 2008 9:44 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Hi Brendan,

check if the index PK_Painting exists and if the id column is really an identity column. If both is correct, try

SET IDENTITY_INSERT Painting OFF

to enable the identity mechanism on that table, maybe it's disabled for some reason.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 02, 2008 6:41 pm 
Newbie

Joined: Wed Feb 20, 2008 8:08 pm
Posts: 10
Thanks Wolli, the database on the server had a different schema I should have checked.


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