Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelpHibernate version: Hibernate 2
Mapping documents: UsageBean.hbm.xml (where <joined-subclass> tag is used).
hibernate.cfg.xml (where database configuration is done)
See , i've successfully done cascade insertion (parent-child) by using
same workspace (same configuration files).
Code between sessionFactory.openSession() and session.close(): SessionFactory fac = getSessionFactory();
Session session = fac.openSession();
net.sf.hibernate.Transaction tx = session.beginTransaction();
//obj.getUsage().setId(6);
/*It is setted here to set primary key of master whose record is
to be upated just for checking*/
obj.setId(6);
System.err.println("Before updation. ");
session.update(obj);
System.err.println("After updation.");
tx.commit();
session.close();
Full stack trace of any exception that occurs:[4/27/05 19:48:57:382 GMT+05:30] 3133b6a0 TransactionMa I net.sf.hibernate.transaction.TransactionManagerLookupFactory instantiated TransactionManagerLookup
[4/27/05 19:48:58:241 GMT+05:30] 3133b6a0 SettingsFacto I net.sf.hibernate.cfg.SettingsFactory Use scrollable result sets: true
[4/27/05 19:48:58:241 GMT+05:30] 3133b6a0 SettingsFacto I net.sf.hibernate.cfg.SettingsFactory Use JDBC3 getGeneratedKeys(): false
[4/27/05 19:48:58:241 GMT+05:30] 3133b6a0 SettingsFacto I net.sf.hibernate.cfg.SettingsFactory Optimize cache for minimal puts: false
[4/27/05 19:48:58:241 GMT+05:30] 3133b6a0 SettingsFacto I net.sf.hibernate.cfg.SettingsFactory Default schema set to: PTT
[4/27/05 19:48:58:241 GMT+05:30] 3133b6a0 SettingsFacto I net.sf.hibernate.cfg.SettingsFactory echoing all SQL to stdout
[4/27/05 19:48:58:241 GMT+05:30] 3133b6a0 SettingsFacto I net.sf.hibernate.cfg.SettingsFactory Query language substitutions: {}
[4/27/05 19:48:58:241 GMT+05:30] 3133b6a0 SettingsFacto I net.sf.hibernate.cfg.SettingsFactory cache provider: net.sf.hibernate.cache.HashtableCacheProvider
[4/27/05 19:48:58:257 GMT+05:30] 3133b6a0 Configuration I net.sf.hibernate.cfg.Configuration instantiating and configuring caches
[4/27/05 19:48:58:554 GMT+05:30] 3133b6a0 SessionFactor I net.sf.hibernate.impl.SessionFactoryImpl building session factory
[4/27/05 19:48:59:882 GMT+05:30] 3133b6a0 SessionFactor I net.sf.hibernate.impl.SessionFactoryObjectFactory Not binding factory to JNDI, no JNDI name configured
[4/27/05 19:48:59:882 GMT+05:30] 3133b6a0 WebSphereTran I net.sf.hibernate.transaction.WebSphereTransactionManagerLookup WebSphere 5.0
[4/27/05 19:48:59:991 GMT+05:30] 3133b6a0 SystemErr R Before updation.
[4/27/05 19:49:00:007 GMT+05:30] 3133b6a0 SystemErr R After updation.
[4/27/05 19:49:00:022 GMT+05:30] 3133b6a0 SystemOut O Hibernate: update PTT.LOGIN set USERID=?, PASSWORD=? where ID=?
[4/27/05 19:49:00:054 GMT+05:30] 3133b6a0 SystemOut O Hibernate: update PTT.LOGIN_CHILD1 set ROLE1=?, ROLE2=?, ROLE3=? where id=?
[4/27/05 19:49:00:069 GMT+05:30] 3133b6a0 SystemOut O Hibernate: update PTT.LOGIN_CHILD1 set ID=null where ID=?
[4/27/05 19:49:00:351 GMT+05:30] 3133b6a0 JDBCException W net.sf.hibernate.util.JDBCExceptionReporter SQL Error: 1407, SQLState: 72000
[4/27/05 19:49:00:398 GMT+05:30] 3133b6a0 JDBCException E net.sf.hibernate.util.JDBCExceptionReporter ORA-01407: cannot update ("PTT"."LOGIN_CHILD1"."ID") to NULL
[4/27/05 19:49:00:413 GMT+05:30] 3133b6a0 JDBCException W net.sf.hibernate.util.JDBCExceptionReporter SQL Error: 1407, SQLState: 72000
[4/27/05 19:49:00:413 GMT+05:30] 3133b6a0 JDBCException E net.sf.hibernate.util.JDBCExceptionReporter ORA-01407: cannot update ("PTT"."LOGIN_CHILD1"."ID") to NULL
[4/27/05 19:49:00:460 GMT+05:30] 3133b6a0 SystemErr R Exception in DataAccess :> net.sf.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
[4/27/05 19:49:00:460 GMT+05:30] 3133b6a0 SystemErr R After save.
[4/27/05 19:49:00:444 GMT+05:30] 3133b6a0 SessionImpl E net.sf.hibernate.impl.SessionImpl Could not synchronize database state with session
Name and version of the database you are using: ORACLE , 8i
The generated SQL (show_sql=true):[4/27/05 19:49:00:022 GMT+05:30] 3133b6a0 SystemOut O Hibernate: update PTT.LOGIN set USERID=?, PASSWORD=? where ID=?
[4/27/05 19:49:00:054 GMT+05:30] 3133b6a0 SystemOut O Hibernate: update PTT.LOGIN_CHILD1 set ROLE1=?, ROLE2=?, ROLE3=? where id=?
[4/27/05 19:49:00:069 GMT+05:30] 3133b6a0 SystemOut O Hibernate: update PTT.LOGIN_CHILD1 set ID=null where ID=?
Debug level Hibernate log excerpt:hi,
I'm having problem while using cascade updation in Hibernate,
Situation is like this :-
Parent table - LOGIN ( Id (pk), UserID (str), Password (str) );
Child table - LOGIN_CHILD1 ( Id(fk), Role1, Role2, Role3 );
( pk > primary key ; fk > foriegn key)
Content of (bean.hbm.xml) is like this ::
*********** from here ************* <?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="hello.UsageBean" table="LOGIN" polymorphism="implicit">
<id name="id" column="ID">
<generator class="increment"/>
</id>
<property name="userid" column="USERID" type="string"/>
<property name="password" column="PASSWORD" type="string"/>
<set name="childbean" lazy="false">
<key column="ID"/>
<one-to-many class="hello.UsageBeanChild"/>
</set>
<joined-subclass name="hello.UsageBeanChild" table="LOGIN_CHILD1">
<key column="id"/>
<property name="role1" column="ROLE1" type="java.lang.String" />
<property name="role2" column="ROLE2" type="java.lang.String" />
<property name="role3" column="ROLE3" type="java.lang.String" />
</joined-subclass>
</class>
</hibernate-mapping>
************ upto here ************* Now when i'm writing :-
***********************************************
session.update(obj);***********************************************
Where (session) is an instance of :
net.sf.hibernate.Session and (obj) is an instance of child bean object.
It's giving
OUTPUT like this ::
1) Hibernate: update PTT.LOGIN set USERID=?, PASSWORD=? where
ID=?
2) Hibernate: update PTT.LOGIN_CHILD1 set ROLE1=?, ROLE2=?,
ROLE3=? where id=?
3) Hibernate: update PTT.LOGIN_CHILD1 set ID=null where ID=? (i think problem is related to this. but not sure )
[4/27/05 19:49:00:351 GMT+05:30] 3133b6a0
JDBCException W net.sf.hibernate.util.JDBCExceptionReporter
SQL Error: 1407, SQLState: 72000
[4/27/05 19:49:00:398 GMT+05:30] 3133b6a0
JDBCException E net.sf.hibernate.util.JDBCExceptionReporter
ORA-01407: cannot update ("PTT"."LOGIN_CHILD1"."ID") to NULL
4)
Exception is ::
net.sf.hibernate.exception.GenericJDBCException:
Could not execute JDBC batch update net.sf.hibernate.impl.SessionImpl Could not synchronize
database state with sessionThis is the Problem .
Please Help me i got my brain stuck in it.