Hello ,
i want to insert values into child table along with parent tables values inserted . i am using one-to-many relationship(Set).
i tried with below code:
parent table mapping:
<class name="EcrLocale" table="ecr_locale"> <id name="ctrycode" column="ctrycode" length="2"> </id> <property name="localeCode" column="locale_code" /> <property name="languageName" column="language_name" /> <property name="decimalPtChar" column="decimal_pt_char" /> <set name="translations" lazy="false"> <key column="ctrycode"/> <one-to-many class="EcrLanguageTranslation"/> </set> </class>
child table mapping:
<class name="EcrLanguageTranslation" table="ecr_language_translation"> <composite-id> <key-property name="englishWord" column="english_word" /> <key-property name="ctrycode" column="ctrycode" /> </composite-id> <property name="foreignWord" column="foreign_word" /> </class>
Java code is :
EcrLocale ecrlocale = new EcrLocale(); ecrlocale.setCtrycode("SR"); ecrlocale.setDecimalPtChar(','); ecrlocale.setLanguageName("Engish S"); ecrlocale.setLocaleCode("S1"); EcrLanguageTranslation elt=new EcrLanguageTranslation(); elt.setCtrycode("SR"); elt.setEnglishWord("hai"); elt.setForeignWord("iah"); Set set=new HashSet(); set.add(elt); ecrlocale.setTranslations(set); Serializable s = session.save(ecrlocale);
the stack trace is:
org.hibernate.StaleStateException: Unexpected row count: 0 expected: 1 at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:27) at org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1039) at org.hibernate.action.CollectionRecreateAction.execute(CollectionRecreateAction.java:26) at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:143) at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297) at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27) at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985) at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333) at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106) at com.ssc.ecr.maint.model.junit.EcrLocaleTest.tearDown(EcrLocaleTest.java:28) at junit.framework.TestCase.runBare(TestCase.java:130) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at junit.framework.TestSuite.runTest(TestSuite.java:208) at junit.framework.TestSuite.run(TestSuite.java:203) at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
_________________ thnx n rgds
cnu.mrj
|