-->
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: One to many mapping problem
PostPosted: Thu Feb 07, 2008 5:46 am 
Newbie

Joined: Thu Feb 07, 2008 2:26 am
Posts: 3
I have two tables :
Session_instance and Centre , the columns are listed below :

TABLE session_instance

FORMAT_NAME ---- NOT NULL ---- VARCHAR2(20)
SESSION_ID ----NOT NULL ----VARCHAR2(5)
CENTRE_ID ---- NOT NULL ----VARCHAR2(5)
CUTOFF_PERIOD ---- NUMBER
RESERVED_PLACES_NUMBER----NUMBER

TABLE centre

CENTRE_ID ---- NOT NULL ---- VARCHAR2(5)
ONLINE_BOOKING_ENABLED ---- NOT NULL----CHAR(3)
WEBSITE----VARCHAR2(1000)

There are some more columns in both the tables

Now the mapping XML is like :

<hibernate-mapping package="org.ba.businesstier.bo">

<class name="CentreOnlineDetailBO" table="centre">
<id name="centreID"
column="centre_id" type="string">
</id>
<property name="onlineBooking" column="online_booking_enabled" type="string"/>
<property name="onlinePayment" column="payment_options" type="string"/>

<set name="centreSessionDetails" table="session_instance"
lazy="true"
inverse="true"
cascade="all, delete-orphan"
sort="unsorted">
<key>
<column name="centreID" not-null="true"/>
</key>
<one-to-many class="CentreSessionDetailsBO"/>
</set>


</class>
</hibernate-mapping>

-----------------------------------------------------------------------------------

<hibernate-mapping package="org.ba.businesstier.bo">
<class name="CentreSessionDetailsBO" table="session_instance">
<!-- <id name="testDate"
column="session_id" type="string">
</id> -->
<composite-id>
<key-property name="centreID" column="centre_id" type="string" />
<key-property name="testDate" column="test_date" type="date"/>
</composite-id>
<property name="cutOffPeriod" column="cutoff_period" type="string"/>
<property name="reservePlaces" column="reserved_places_number" type="string"/>
</class>
</hibernate-mapping>

All the Properties(gettters and setters) are covered in the BO.
I dont have the session ID , its not needed i just need to update all the sessions for a given centre in session_instance table ,thats why dont represent it in the XML

Now as u notice and as i had mentioned there are many other columns in both the tables but i dont need that data as such, so i have only those that are required in the XML and the BO's.

Now when i set all the values are try to update ( i dont have to insert in my requirement ) . I only do a update , so that both the tables are updated :

I get a error stating that

Caused by: java.sql.BatchUpdateException: ORA-01400: cannot insert NULL into ("C
A_ADMIN"."SESSION_INSTANCE"."FORMAT_NAME")

why is this happening ???? Any clues would be very helpful.. I am new to Hibernate so it could even be very very trivial :-)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 08, 2008 6:04 pm 
Newbie

Joined: Tue Feb 05, 2008 11:16 am
Posts: 5
Quote:
Caused by: java.sql.BatchUpdateException: ORA-01400: cannot insert NULL into ("CA_ADMIN"."SESSION_INSTANCE"."FORMAT_NAME")


This usually indicates you are trying to save a 'null' value in a NOT NULL column. Indeed that column is NOT NULL in the table definition. My theory is that since you have not included SESSION_INSTANCE.FORMAT_NAME in your mapping of the CentreSessionDetailsBO object, Hibernate does not know how to update that field. Instead Hibernate will try to set FORMAT_NAME to 'null', and the database won't allow that and thus the exception.

I would add the FORMAT_NAME to your CentreSessionDetailsBO mapping, make sure your updates do not set it to null, and see if the problem is gone.

Frank


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.