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:
|