-->
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: SQL Exception on a NULL index when using List association.
PostPosted: Thu Jan 17, 2008 4:13 pm 
Newbie

Joined: Thu Jan 10, 2008 11:33 pm
Posts: 8
Hello and thanks for any help!

When trying to use a list construct, the index column is null. The database tables map a one-to-many relationship between a Document table and a Page table. There may be 1...* pages in a document, but the order of the pages needs to be preserved.

I'm not using a mapping table, but do I even need to for list.

Any ideas?

-K

Hibernate version:1.2.0.400

Mapping documents:

Here's for the Document.hbm.xml:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false">
<class name="PersistenceExperiments.Document, PersistenceExperiments" table="Document">
<id name="Id" column="Id" access="nosetter.camelcase">
<generator class="native" />
</id>

<list name="Pages" access="nosetter.camelcase" cascade="all" table="Page">
<key column="DocumentId" />
<index column="Position" />
<one-to-many class="PersistenceExperiments.Page, PersistenceExperiments"/>
</list>

<property name="Name" column="Name" type="String" />
</class>
</hibernate-mapping>

And for Page.hbm.xml:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false">
<class name="PersistenceExperiments.Page, PersistenceExperiments" table="Page">
<id name="Id" column="Id" access="nosetter.camelcase">
<generator class="native" />
</id>
<property name="Randomize" column="Randomize" type="Boolean"/>
</class>
</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():

Document doc = new Document();
doc.Name = "Doc with pages";
doc.AddPage();

ISession session = SessionManager.Instance.GetSession();
ITransaction tran = session.BeginTransaction();

try
{
session.Save(doc);
tran.Commit();
}
catch(Exception ex)
{
throw;
}



Stack trace of any exception that occurs:

NHibernate.ADOException : could not insert: [PersistenceExperiments.Page][SQL: INSERT INTO Page (Randomize) VALUES (?)]
----> System.Data.SqlClient.SqlException : Cannot insert the value NULL into column 'Position', table 'NHibernate_Testbed.dbo.Page'; column does not allow nulls. INSERT fails.



Name and version of the database you are using:SQLServer 2005

The generated SQL (show_sql=true):
INSERT INTO Page (Randomize) VALUES (?)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 17, 2008 4:59 pm 
Newbie

Joined: Thu Jan 10, 2008 11:33 pm
Posts: 8
I forgot to add that when I turn off the NOT NULL constraint on my Page table, the index column is set. But, it seems like the index should be known during the INSERT call, so I imagine there is a directive in the xml that I'm lacking. I don't want my index to allow nulls in the db table.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 18, 2008 7:50 pm 
Newbie

Joined: Thu Jan 10, 2008 11:33 pm
Posts: 8
After digging around the forums some more, I think the answer is: "it's not a bug, it's a feature."

This thread covers the issue, for those having the same problem.

http://forum.hibernate.org/viewtopic.ph ... nhibernate

Though it isn't ideal, I can deal with it.


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.