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: Could not insert exception
PostPosted: Tue Apr 03, 2007 5:19 am 
Newbie

Joined: Tue Apr 03, 2007 5:05 am
Posts: 4
Hi, probably a newby question , but i'm new to NHibernate and google leaves me clueless.

The problem is that everything seems to be allright, but then it throws an exception like:

could not insert: [TestProject.Cat][SQL: INSERT INTO Cat (Name, Sex, Weight) VALUES (?, ?, ?)]

Notice the questionmarks.. The Cat object that goes in, has its values set.
I basically used the example of the nhibernate_reference.pdf.

I'm using NHibernate 1.2 on VS2005. tried the mapping from the reference, also generated the mappings and objects with NHibernate plugin for VS 2005, but the exception remains.

It's not a web project by the way, but a windows forms application.

Configuration in app.config

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.connection_string">Data Source=myservername\SQLEXPRESS;Initial Catalog=Testdb;Integrated Security=True</property>
<mapping assembly="TestProject" />
</session-factory>
</hibernate-configuration>

The mapping and persistant object (Cat) is from the reference. I also tried to make the properties virtual, with no success.

Please help,

Frank


Top
 Profile  
 
 Post subject: no one ?
PostPosted: Fri Apr 06, 2007 4:27 am 
Newbie

Joined: Tue Apr 03, 2007 5:05 am
Posts: 4
Can't believe that nobody has at least a thought on this ...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 06, 2007 5:14 am 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
Well the exception you've posted only indicates that NHibernate couldn't insert the row into the DB server's table - you've omitted any additional information that might help us to pinpoint your problem.

Perhaps your table definition is not correct, or you have a typo in your mapping? Perhaps there's a problem with your connection string?

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 06, 2007 5:15 am 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
Well the exception you've posted only indicates that NHibernate couldn't insert the row into the DB server's table - you've omitted any additional information that might help us to pinpoint your problem.

Perhaps your table definition is not correct, or you have a typo in your mapping? Perhaps there's a problem with your connection string?


Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 06, 2007 5:42 am 
Newbie

Joined: Tue Apr 03, 2007 5:05 am
Posts: 4
Ok,

The connectionstring should be ok, i can use it in another test app. Unless NHibernate requires a special format of connection string.

My mapping file is from the reference:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="QuickStart" assembly="QuickStart">
<class name="Cat" table="Cat">
<!-- A 32 hex character is our surrogate key. It's automatically
generated by NHibernate with the UUID pattern. -->
<id name="Id">
<column name="CatId" sql-type="char(32)" not-null="true"/>
<generator class="uuid.hex" />
</id>
<!-- A cat has to have a name, but it shouldn' be too long. -->
<property name="Name">
<column name="Name" length="16" not-null="true" />
</property>
<property name="Sex" />
<property name="Weight" />
</class>
</hibernate-mapping>

My Databasetable
Cat:
CatId char(32) (primary key)
Name nvarchar(16)
Sex nchar(1)
Weight real


----
The fact that the query shows question marks in stead of values, let me believe that NHibernate can't get the values from the object. Or is this a regular error?

Hope this gives enough info

Frank


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 06, 2007 6:37 am 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
No, the question marks indicate that the values are being set using parameters rather than being coded directly into the SQL - which is a good thing.

I think the debug you're seeing isn't the actual final SQL that's being generated, but a higher level representation of it. You might want to turn on SQL logging or get the full stack trace of the error which might have additional information in it.

Cheers,

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 06, 2007 7:37 am 
Newbie

Joined: Tue Apr 03, 2007 5:05 am
Posts: 4
Ok, I thought the questionmarks were NULL values.
The SQL exception is that CatId cannot be null.

Due to a new project i can't experiment more on this right now. Hope I can get this running later on.

Thnx for the help so far

Frank


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.