-->
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.  [ 10 posts ] 
Author Message
 Post subject: Could not insert into joint subclass
PostPosted: Mon Sep 27, 2004 12:07 pm 
Beginner
Beginner

Joined: Tue Sep 21, 2004 1:03 pm
Posts: 21
Hi,
I'm facing a problem where I'm not able to insert into the table which is joined subclass of a class and has the same primary key as the parent class. Parent class get the generated primary key and the same key should also be inseted into the child class. Could any one please help me out , as It's taking too much time to move forwrd.


Thanks & Regards,
Irfan




Hibernate version:2.1.6

Mapping documents:<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class name="com.irfan.promotion.instance.DefaultPromotion" table="promo">
<id name="id">
<generator class="com.irfan.promotion.persistence.hibernate.HibernateIDGenerator">
<param name="table">promo</param>
<param name="maxCachedIds">100</param>
</generator>
</id>
<property name="promotionTypeLayerId" column="promo_type_layer_id" type="int" />
<joined-subclass name="com.irfan.sybil.promotion.instance.DiscountStayPromotion" table="promo_discount_stay">
<key column="promo_id"/>
<property name="discount" column="discount" type="float" />
<property name="fullPriceNights" column="full_price_nights" type="int" />
<property name="discountPriceNights" column="discount_nights" type="int" />
</joined-subclass>
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
hibernateSession.save(Promotion());



Full stack trace of any exception that occurs:Hibernate: insert into promo (promo_type_layer_id, id) values (?, ?)
Hibernate: insert into promo_discount_stay (discount, full_price_nights, discount_nights, promo_id) values (?, ?, ?, ?)
2004-09-27 15:09:40,105 WARN [net.sf.hibernate.util.JDBCExceptionReporter] SQL Error: -691, SQLState: 23000
2004-09-27 15:09:40,106 ERROR [net.sf.hibernate.util.JDBCExceptionReporter] Missing key in referenced table for referential constraint (iansari.r17403_15625).
2004-09-27 15:09:40,106 WARN [net.sf.hibernate.util.JDBCExceptionReporter] SQL Error: -111, SQLState: IX000
2004-09-27 15:09:40,106 ERROR [net.sf.hibernate.util.JDBCExceptionReporter] ISAM error: no record found.
2004-09-27 15:09:40,112 WARN [net.sf.hibernate.util.JDBCExceptionReporter] SQL Error: -691, SQLState: 23000
2004-09-27 15:09:40,112 ERROR [net.sf.hibernate.util.JDBCExceptionReporter] Missing key in referenced table for referential constraint (iansari.r17403_15625).
2004-09-27 15:09:40,112 WARN [net.sf.hibernate.util.JDBCExceptionReporter] SQL Error: -111, SQLState: IX000
2004-09-27 15:09:40,112 ERROR [net.sf.hibernate.util.JDBCExceptionReporter] ISAM error: no record found.
2004-09-27 15:09:40,116 ERROR [net.sf.hibernate.util.JDBCExceptionReporter] could not insert: [com.irfan.promotion.instance.DiscountStayPromotion#23687]
java.sql.SQLException: Missing key in referenced table for referential constraint (iansari.r17403_15625).
at com.informix.jdbc.IfxSqli.addException(IfxSqli.java:2996)
at com.informix.jdbc.IfxSqli.receiveError(IfxSqli.java:3310)
at com.informix.jdbc.IfxSqli.dispatchMsg(IfxSqli.java:2263)
at com.informix.jdbc.IfxSqli.receiveMessage(IfxSqli.java:2183)
at com.informix.jdbc.IfxSqli.executeCommand(IfxSqli.java:692)
at com.informix.jdbc.IfxResultSet.executeUpdate(IfxResultSet.java:308)
at com.informix.jdbc.IfxStatement.executeUpdateImpl(IfxStatement.java:857)
at com.informix.jdbc.IfxPreparedStatement.executeUpdate(IfxPreparedStatement.java:279)
at net.sf.hibernate.persister.NormalizedEntityPersister.insert(Unknown Source)
at net.sf.hibernate.persister.NormalizedEntityPersister.insert(Unknown Source)


Name and version of the database you are using:Informix 9.4

The generated SQL (show_sql=true):Hibernate: insert into promo (promo_type_layer_id, id) values (?, ?)
Hibernate: insert into promo_discount_stay (discount, full_price_nights, discount_nights, promo_id) values (?, ?, ?, ?)


Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 27, 2004 12:10 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
well, i guess it looks like probably your custom id generator is at fault, can you reproduce it with one of the built-in id generators?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 27, 2004 12:20 pm 
Beginner
Beginner

Joined: Tue Sep 21, 2004 1:03 pm
Posts: 21
gavin wrote:
well, i guess it looks like probably your custom id generator is at fault, can you reproduce it with one of the built-in id generators?



Quote:
Hi Gavin,

The problem doesn't seems to be with the IDGenerator, that's working fine and it's just for the caching purpose as we are getting this from the database.

The problem seems to be in the seetings where I'm trying to save the contents into promotion table and subsequently into prom_discount_stay table.

below is the tables structure , which might help you to understand the problem.


promo table
------------------
id
promo_type_layer_id
-------------------------

promo_discount_stay
-----------------------------
promo_id (PK and FK referencing the id of the upper table)

field1.
field2
field3.
----------------------------


At the run time there is two insert statement one in promo(here id get generated) and other in promo_discount_stay (the same id has to be use)

Seems it may help to you understand the problem.

Thanks for your help.

Regards,
Irfan[/i][/quote][/code]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 27, 2004 12:22 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I understand what you are trying to do. Did you try my suggestion yet?


Top
 Profile  
 
 Post subject: same problem
PostPosted: Mon Sep 27, 2004 12:41 pm 
Beginner
Beginner

Joined: Tue Sep 21, 2004 1:03 pm
Posts: 21
Gavin,

I'm still getting the same error , which generator class do you want me try for id generation.

Could you please tell me , what do you think the problem is and how it's related to ID generator.


Thanks & Regards,
Irfan


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 27, 2004 12:47 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Enable logging, let's see what values are bound to the prepared statement.


Top
 Profile  
 
 Post subject: Log.debug
PostPosted: Mon Sep 27, 2004 1:05 pm 
Beginner
Beginner

Joined: Tue Sep 21, 2004 1:03 pm
Posts: 21
Can I print the System.out.println statement to see the executino step in the code.

I have tried to use log.debug ("Irfan") in between the code , but it's not printing at all. Otherwise it's bounding to correct value.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 27, 2004 1:07 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I mean enable *Hibernate's* log. Using log4j


Top
 Profile  
 
 Post subject: Sorted out, but introduces one other problem
PostPosted: Mon Sep 27, 2004 2:31 pm 
Beginner
Beginner

Joined: Tue Sep 21, 2004 1:03 pm
Posts: 21
Quote:
Hi Gavin,

Now , I'm able to insert the value into the table, but the it's turn into second problem.

For the same fields value it's inserting a new row into a table. How can I prevent to insert a new row , if the supplied value (record ) is already existing in the database except the primary key.

Thanks & Regards,
Irfan
[/quote]


Top
 Profile  
 
 Post subject: Re: Sorted out, but introduces one other problem
PostPosted: Tue Sep 28, 2004 9:47 am 
Beginner
Beginner

Joined: Tue Sep 21, 2004 1:03 pm
Posts: 21
How can I prevent to insert a new record into a table , if it has already a same row.


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