-->
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.  [ 2 posts ] 
Author Message
 Post subject: Unable to insert into Oracle
PostPosted: Thu Aug 05, 2010 3:48 am 
Newbie

Joined: Thu Aug 05, 2010 3:38 am
Posts: 2
It's my first time using NHibernate.

I had followed the tutorial over a nforge and had get myself started with my project. However I encountered an error which I do not know what is it all about.

Basically there are 2 classes for now. My database has a few more but I am working on this 2 first.
Class 1 -- WaterBody
Class 2 -- Exceedance

the relation between this 2 class is a one waterbody is to many exceedance.

this is my mapping file for the both of them ( I have no idea if I am doing it correctly)

Exceedance.hbm.xml

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="GEMSystem"
namespace="GEMSystem.Models.Entities">
<class name="Exceedance" table="Exceedance">
<id name ="ExceedanceId" column="ExceedanceId" type="int">
<generator class="sequence"/>
</id>
<property name="WaterBodyId">
<column name="WaterBodyId" unique-key="WaterbodyParameter"/>
</property>
<property name ="Parameter">
<column name="Parameter" unique-key="WaterbodyParameter"/>
</property>

<property name ="Min" />
<property name="Max" />

<many-to-one name="WaterBody"
class="WaterBody"
column="WaterBodyId"
cascade="all"/>
</class>

</hibernate-mapping>

----------------------------------------------------------------------------------------------------------
WaterBody.hbm.xml

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="GEMSystem"
namespace="GEMSystem.Models.Entities">

<class name="WaterBody">
<id name="WaterBodyId" type="string" length="6">
<generator class="assigned" />
</id>
<property name="Name" />
<property name="WaterBodyType" />
</class>
</hibernate-mapping>
----------------------------------------------------------------------------------------------------------
My SQL Create statement for both tables

CREATE TABLE WaterBody
( WaterBodyId char(6) PRIMARY KEY
, Name varchar2(50)
, WaterBodyType char(2)
);


CREATE TABLE Exceedance
( ExceedanceId number PRIMARY KEY
, waterBodyId char(6) REFERENCES WaterBody(waterBodyId)
, parameter varchar2(30)
, min number
, max number
, UNIQUE ( waterBodyId , parameter )
);

----------------------------------------------------------------------------------------------------------
For now, I am able to retrieve any records from both the tables but when I try to add a exceedance record, it give me this error

I would like to have an auto-increment value of my ExceedanceId.

"Invalid index 5 for this OracleParameterCollection with Count=5."

Please help. Thank you


Top
 Profile  
 
 Post subject: Re: Unable to insert into Oracle
PostPosted: Thu Aug 05, 2010 4:10 am 
Newbie

Joined: Thu Aug 05, 2010 3:38 am
Posts: 2
I think i manage to solve this error. It seems like the error is caused by the many-to-one relationship over at the mapping file. i inserted this,

<many-to-one name="WaterBody"
class="WaterBody"
column="WaterBodyId"
insert ="false"
update="false"/>

insert = false and update = false. (A solution I found somewhere).

Can anyone care to explain why do I have to put those 2 lines of codes? Will it affect my future development?


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