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.  [ 4 posts ] 
Author Message
 Post subject: Error saving to oracle database
PostPosted: Mon Mar 03, 2008 2:58 pm 
Newbie

Joined: Wed Feb 27, 2008 4:20 pm
Posts: 3
I'm new to Nhibernate and am using it in C# to access an Oracle database. I can make queries to the database correctly and I get back valid results. However, when I try to save a new object into the database, I always get an error.

This is my mapping file:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="WebsterBank.QualityAssurance.WtfInterface.Data"
assembly="WtfInterface" default-lazy="false">

<class name="Host" table="WIL_HOSTS">
<id name="ID" column="WIL_HOST_ID" type="Int32">
<generator class="assigned"/>
</id>
<property name="Name" column="NAME" type="String"/>
<property name="Address" column="ADDRESS" type="String"/>
<property name="DataSetID" column="DATA_SET_ID" type="Int32"/>
<property name="BypassSecurity" column="BYPASS_SECURITY" type="String"/>
<property name="Type" column="TYPE" type="String"/>
</class>
</hibernate-mapping>


My code that tries to save the object is the following:

public void addHost(Host hostToAdd) {
ISessionFactory factory = getSessionFactory();
ISession session = factory.OpenSession();
ITransaction tx = session.BeginTransaction();
session.Save(hostToAdd);
tx.Commit();
session.Flush();
session.Close();
factory.Close();
}


I get an error whenever the code tries to execute the tx.commit() statement. The error is the following:

NHibernate.ADOException: could not insert: [WebsterBank.QualityAssurance.WtfInterface.Data.Host#47][SQL: INSERT INTO WIL_HOSTS (NAME, ADDRESS, DATA_SET_ID, BYPASS_SECURITY, TYPE, WIL_HOST_ID) VALUES (?, ?, ?, ?, ?, ?)] ---> System.Data.OracleClient.OracleException: ORA-01400: cannot insert NULL into ("WIL_WTF"."WIL_HOSTS"."MODIFIABLE")

Does anyone know what might be causing this and/or a solution to this?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 03, 2008 3:06 pm 
Regular
Regular

Joined: Wed Jan 25, 2006 1:11 am
Posts: 118
Location: Copenhagen, Denmark
The oracle message means that you cannot insert null into the column Modifiable in the wil_hosts table, so either it should have a default value in the database or you need to map it and supply a value in your objects.


Top
 Profile  
 
 Post subject: Error saving to oracle database
PostPosted: Mon Mar 03, 2008 3:08 pm 
Senior
Senior

Joined: Thu Jun 21, 2007 8:03 am
Posts: 127
Location: UK
Hi,

The error suggests that there is a column 'MODIFIABLE' in your database, which is not mentioned in the mapping.

Can you post the details of the Oracle table? Obviously, any not-null columns would require a value to be inserted.

Regards,
Richard


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 03, 2008 3:15 pm 
Newbie

Joined: Wed Feb 27, 2008 4:20 pm
Posts: 3
thanks for the help. I should have noticed somethign this trivial.


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