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.  [ 7 posts ] 
Author Message
 Post subject: Persisted object data is not appearing in DB
PostPosted: Sat Jan 06, 2007 1:37 pm 
Newbie

Joined: Thu Jan 04, 2007 10:50 am
Posts: 8
Hello

My problem is that once I've saved an object to my database (a sql server 2005 mdf file using the mssql2000 dialect) it never seems to actually appear when I look in the table data (my empty table is still empty!)

I was using an identity generator but this kept telling me that I couldn't insert null for the primary key (I thought that MS SQL 2005 would generate this for me...). So I used increment and now everything runs through fine without any exceptions.

im simply doing:
Code:
transaction = session.BeginTransaction();

//populate object

session.save(myObject)

transaction.commit()


I checked the WasCommitted property on transaction at runtime and it is always set to true which is good. However the data just isnt appearing in my table! The mapping files all seem okay too...

Has anyone experienced this or get any suggestions?

Kind Regards

Tom.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 06, 2007 1:44 pm 
Regular
Regular

Joined: Wed Jun 21, 2006 3:13 pm
Posts: 110
What is your mapping?

Here is mine, it's running just fine against 2005 with the 2000 dialect:

Code:
      <id name="Id" type="Int32" unsaved-value="0" access="nosetter.camelcase">
         <column name="kennelId" not-null="true" unique="true" />
         <generator class="identity" />
      </id>


Also, either set up log4net, set your log level to debug, and then set show_sql=true in your nhibernate config. Or, open sql profiler and turn on a trace and see what sql is being sent to the db.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 06, 2007 2:03 pm 
Newbie

Joined: Thu Jan 04, 2007 10:50 am
Posts: 8
Thanks for the quick response. I changed my mapping to adhere to your style, but now I am getting

{"Cannot insert the value NULL into column 'Id', table 'E:\\USERS\\TOM\\DOCUMENTS\\PROPERTYTRACKER.MDF.dbo.EstateAgents'; column does not allow nulls. INSERT fails.\r\nThe statement has been terminated."}

My EstateAgent class has a private field

Code:
private int _id;


and a public property

Code:
public int Id
{
  get { return _id; }
  set { _id = value; }
}


My mapping file now has this (based on your one)

Code:
<id name="Id" type="int" unsaved-value="0" access="nosetter.camelcase-underscore">
      <column name="Id" not-null="true" unique="true" />
      <generator class="identity"/>
</id>


Can't see what I'm doing wrong!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 06, 2007 2:20 pm 
Regular
Regular

Joined: Wed Jun 21, 2006 3:13 pm
Posts: 110
Can you script out your table?

Since I've done it so many times, the first thing I'd look at would be if the column is truly an identity column


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 06, 2007 2:26 pm 
Newbie

Joined: Thu Jan 04, 2007 10:50 am
Posts: 8
Hello

there doesnt seem to be an option for scripting it out. However my log4net gave me this

18:23:36.718 [5436] DEBUG NHibernate.SQL - INSERT INTO EstateAgents (County, Country, Email, Address1, Name, Postcode, Fax, Town, Address2, Telephone) VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9); select SCOPE_IDENTITY()

....

18:23:37.000 [5436] DEBUG NHibernate.Util.ADOExceptionReporter - could not insert: [PropertyTrackerBusiness.Domain.EstateAgent]
System.Data.SqlClient.SqlException: Cannot insert the value NULL into column 'Id', table 'E:\USERS\TOM\DOCUMENTS\PROPERTYTRACKER.MDF.dbo.EstateAgents'; column does not allow nulls. INSERT fails.
The statement has been terminated.


I checked the IsIdentity on the Id via vs 2005 and it is set to 'Yes'. It is set to increment of 1.

The INSERT statement looks ok to me?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 06, 2007 2:36 pm 
Regular
Regular

Joined: Wed Jun 21, 2006 3:13 pm
Posts: 110
LordBlackadder wrote:
Hello

there doesnt seem to be an option for scripting it out. However my log4net gave me this

18:23:36.718 [5436] DEBUG NHibernate.SQL - INSERT INTO EstateAgents (County, Country, Email, Address1, Name, Postcode, Fax, Town, Address2, Telephone) VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9); select SCOPE_IDENTITY()


Well, I just tried to replicate your error but it turns out that I don't have Express loaded so I can't add an .mdf file to my solution (stupid thing, I've got SQL Server 2005 standard running).

Anyway, my hunch is that, if you tried to run that from a query window against the db you'd get the same error. I forget, does vs 2005 give you a query window? You might want to try sql server 2005 express management studio as well.

For whatever reason, that column doesn't seem like it's an identity column. If you go back to an assigned identity (just change generator class="identity" to "assigned"), what is the SQL in your log file?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 06, 2007 2:51 pm 
Newbie

Joined: Thu Jan 04, 2007 10:50 am
Posts: 8
ok well i replaced the parameters with values and ran from the query window in vs 2005

Code:
INSERT INTO EstateAgents
                         (County, Name, Email, Address1, Postcode, Fax, Town, Address2, Telephone)
VALUES        ('aa', 'aa', 'aa', 'aa', 'aa', 'aa', 'aa', 'aa', 'aa')



and this worked ok..... the data then appeared as expected, with the id column set to 1 automatically.

V. Confusing!!


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