-->
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.  [ 5 posts ] 
Author Message
 Post subject: NHibernate not generating value on insert
PostPosted: Mon Dec 08, 2008 9:52 am 
Newbie

Joined: Mon Dec 08, 2008 9:42 am
Posts: 3
Hi there,

I've been having real trouble mapping one of my classes. Everything looks fine to me and I can't work out why it's not mapping properly. I have about 20 other classes which are all mapping fine.

The problem is that NHibernate doesn't seem to be generating a value for the RowAdded and RowModified fields, which have been set to generated="insert" and generated="always" respectively. What is even more puzzling is that the fields are not being included in the query generated by NHibernate.

These fields are not nullable and thus a value must be generated for the insert to proceed. I'm not sure why it's not working...

All help appreciated!

Thanks,
Andrew.


Hibernate version: NHibernate 2.0.1.4000
Name and version of the database you are using: Microsoft SQL Server Express 2005

The generated SQL (show_sql=true):
NHibernate: INSERT INTO ServiceRate (StartDate, AdultPrice, ChildPrice, FamilyPrice, FamAdultPrice, FamChildPrice, ServiceGUID, ModifiedByUser, RateGUID) VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8); @p0 = '9/12/2008 12:00:00 AM', @p1 = '55.0', @p2 = '22.0', @p3 = '100.0', @p4 = '0.0', @p5 = '0.0', @p6 = '8aab58c9-bc9c-41a9-918b-06376dde9b32', @p7 = 'AH', @p8 = '7db97d7f-c95f-4a1c-8696-dc478a868c27'



Mapping documents:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="BookingsBO" assembly="BookingsBO">

<class name="ServiceRate" lazy="false">

<id name="GUID" column="RateGUID" type="guid" unsaved-value="">
<generator class="guid" />
</id>

<version name="RowModified" type="timestamp" generated="always" />
<property name="StartDate" type="Date" not-null="true" access="field.camelcase-underscore" />
<property name="AdultPrice" type="Decimal" not-null="true" access="field.camelcase-underscore" />
<property name="ChildPrice" type="Decimal" not-null="true" access="field.camelcase-underscore" />
<property name="FamilyPrice" type="Decimal" not-null="true" access="field.camelcase-underscore" />
<property name="FamAdultPrice" type="Decimal" not-null="true" access="field.camelcase-underscore" />
<property name="FamChildPrice" type="Decimal" not-null="true" access="field.camelcase-underscore" />
<many-to-one name="Service" class="Service" column="ServiceGUID" not-null="true" access="field.camelcase-underscore" />
<property name="RowAdded" type="timestamp" generated="insert" not-null="true" />
<property name="ModifiedByUser" type="string" length="10" not-null="true" />

</class>

</hibernate-mapping>



Full stack trace of any exception that occurs:

TestCase 'BookingsBO.NHibernateTests.ServiceRateTest.CreateServiceRateWithAllData'
failed: NHibernate.Exceptions.GenericADOException : could not insert: [BookingsBO.ServiceRate][SQL: INSERT INTO ServiceRate (StartDate, AdultPrice, ChildPrice, FamilyPrice, FamAdultPrice, FamChildPrice, ServiceGUID, ModifiedByUser, RateGUID) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)]
----> System.Data.SqlClient.SqlException : Cannot insert the value NULL into column 'RowAdded', table 'BookingSystem.dbo.ServiceRate'; column does not allow nulls. INSERT fails.
The statement has been terminated.
at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Boolean[] notNull, Int32 j, SqlCommandInfo sql, Object obj, ISessionImplementor session)
at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Object obj, ISessionImplementor session)
at NHibernate.Action.EntityInsertAction.Execute()
at NHibernate.Engine.ActionQueue.Execute(IExecutable executable)
at NHibernate.Engine.ActionQueue.ExecuteActions(IList list)
at NHibernate.Engine.ActionQueue.ExecuteActions()
at NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource session)
at NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent event)
at NHibernate.Impl.SessionImpl.Flush()
C:\Users\Andrew\Documents\Visual Studio 2008\Projects\BCBookingSystem3\BookingsBO\NHibernateTests\ServiceRateTest.cs(35,0): at BookingsBO.NHibernateTests.ServiceRateTest.CreateServiceRateWithAllData()
--SqlException
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.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.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at NHibernate.AdoNet.AbstractBatcher.ExecuteNonQuery(IDbCommand cmd)
at NHibernate.AdoNet.NonBatchingBatcher.AddToBatch(IExpectation expectation)
at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Boolean[] notNull, Int32 j, SqlCommandInfo sql, Object obj, ISessionImplementor session)


Top
 Profile  
 
 Post subject: Solved.
PostPosted: Tue Dec 09, 2008 7:27 am 
Newbie

Joined: Mon Dec 08, 2008 9:42 am
Posts: 3
Oops! It seems this was my database's fault not NHibernates. Problem solved.


Top
 Profile  
 
 Post subject: what was the problem of your db?
PostPosted: Sun Jan 11, 2009 5:01 pm 
Newbie

Joined: Sun Jan 11, 2009 5:00 pm
Posts: 2
I have same problem. And i couldn't figure out. Please share with us, what was the problem on your db?

_________________
Ich bin ich, und du?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 12, 2009 3:00 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Generated means that the database is generating the value and nhibernate will refresh the object after insert/update. Probably your database does not generate the value.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: soved
PostPosted: Mon Jan 12, 2009 1:03 pm 
Newbie

Joined: Sun Jan 11, 2009 5:00 pm
Posts: 2
Table name was wrong :)


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