-->
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.  [ 6 posts ] 
Author Message
 Post subject: Problem with Many to One/One to Many - Parent not found
PostPosted: Mon Feb 06, 2006 5:27 pm 
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp





Hibernate version:
3.1.1
Mapping documents:
------ Person---------

<hibernate-mapping>
<class name="com.everware.component.unittest.person.Person" table="Person">
<id column="InstanceID" name="instanceID" type="integer" unsaved-value="null">
<generator class="native" />
</id>
<property column="ID_FORMAT_CODE" insert="true" name="idFormatCode" not-null="false" type="string" unique="false" update="true" />
<property column="RELIGION_CODE" insert="true" name="religionCode" not-null="false" type="string" unique="false" update="true" />
<property column="OBSOLETE_IND" insert="true" name="obsoleteIndicator" not-null="false" type="string" unique="false" update="true" />
<property column="NICKNAME" insert="true" name="nickname" not-null="false" type="string" unique="false" update="true" />
<property column="CREATED_USERID" insert="true" name="createdUserID" not-null="true" type="string" unique="false" update="true" />
<property column="PREVIOUS_SURNAME" insert="true" name="previousSurname" not-null="false" type="string" unique="false" update="true" />
<property column="INCOME_AMT" insert="true" name="incomeAmount" not-null="false" type="double" unique="false" update="true" />
<property column="LANGUAGE_PREF_CODE" insert="true" name="languagePreferenceCode" not-null="false" type="string" unique="false" update="true" />
<property column="SURNAME" insert="true" name="surname" not-null="true" type="string" unique="false" update="true" />
<property column="FIRST_NAME" insert="true" name="firstName" not-null="true" type="string" unique="false" update="true" />
<property column="DATE_OF_BIRTH" insert="true" name="dateOfBirth" not-null="false" type="date" unique="false" update="true" />
<property column="salutation" insert="true" name="salutation" not-null="true" type="string" unique="false" update="true" />
<property column="ID_VALUE" insert="true" name="idValue" not-null="false" type="string" unique="false" update="true" />
<property column="MARITAL_STATUS_CODE" insert="true" name="maritalStatusCode" not-null="false" type="string" unique="false" update="true" />
<property column="LAST_UPDATED_TS" insert="true" name="lastUpdatedTimestamp" not-null="true" type="date" unique="false" update="true" />
<property column="DATE_OF_DEATH" insert="true" name="dateOfDeath" not-null="false" type="date" unique="false" update="true" />
<property column="GENDER_CODE" insert="true" name="genderCode" not-null="true" type="string" unique="false" update="true" />
<property column="CREATED_TS" insert="true" name="createdTimestamp" not-null="true" type="date" unique="false" update="true" />
<property column="ETHNICITY_CODE" insert="true" name="ethnicityCode" not-null="false" type="string" unique="false" update="true" />
<property column="LAST_UPDATED_USERID" insert="true" name="lastUpdatedUserID" not-null="true" type="string" unique="false" update="true" />
<property column="NAME_SUFFIX_CODE" insert="true" name="nameSuffixCode" not-null="false" type="string" unique="false" update="true" />
<property column="ID_Type_Code" insert="true" name="idTypeCode" not-null="false" type="string" unique="false" update="true" />
<property column="INCOME_FREQ_CODE" insert="true" name="incomeFrequencyCode" not-null="false" type="string" unique="false" update="true" />
<property column="MIDDLE_NAME" insert="true" name="middleName" not-null="false" type="string" unique="false" update="true" />
<property column="socialSecurityNum" insert="true" name="socialSecurityNum" not-null="false" type="string" unique="false" update="true" />
<set cascade="none" inverse="true" name="Addresss">
<key column="InstanceID" />
<one-to-many class="com.everware.component.unittest.person.Address" />
</set>
</class>
</hibernate-mapping>


------------- Address -------------

<hibernate-mapping>
<class name="com.everware.component.unittest.person.Address" table="Address">
<id column="InstanceID" name="instanceID" type="integer" unsaved-value="null">
<generator class="native" />
</id>
<property column="address1" insert="true" name="address1" not-null="false" type="string" unique="false" update="true" />
<property column="address2" insert="true" name="address2" not-null="false" type="string" unique="false" update="true" />
<property column="city" insert="true" name="city" not-null="false" type="string" unique="false" update="true" />
<property column="state" insert="true" name="state" not-null="false" type="string" unique="false" update="true" />
<property column="zip" insert="true" name="zip" not-null="false" type="string" unique="false" update="true" />
<many-to-one cascade="none" class="com.everware.component.unittest.person.Person" name="Person">
<column name="Person"/>
</many-to-one>
<query name="findAll"><![CDATA[from Address address order by address.id asc]]></query>
</class>
</hibernate-mapping>





Code between sessionFactory.openSession() and session.close():


------------ Cactus Test Class -----------

...
persondao.saveOrUpdate(person);


...
Address address = new Address();
address.setAddress1(addresses1[i % addresses1.length]);
address.setAddress2(addresses2[i % addresses2.length]);
address.setCity(cities[i % cities.length]);
address.setState(states[i % states.length]);
address.setZip(zips[i % zips.length]);

address.setPerson(person);
addressdao.saveOrUpdate(address);

/************************************************
persondao and addressdao extend a baseRootDao class
methods delagate to root class
/***********************************************

--------------- BaseRootDao-----------------------

protected void saveOrUpdate(Object obj) throws HibernateException {
Transaction t = null;
Session s = null;
try {
s = getSession();
t = beginTransaction(s);
saveOrUpdate(obj, s);
commitTransaction(t);
}
catch (HibernateException e) {
if (null != t) t.rollback();
throw e;
}
finally {
closeSession();
}
}




Full stack trace of any exception that occurs:

Name and version of the database you are using:

Oracle 9.0.1

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


16:12:28,468 DEBUG SQL:346 - select hibernate_sequence.nextval from dual
16:12:28,468 DEBUG SQL:346 - insert into Person (ID_FORMAT_CODE, RELIGION_CODE,
OBSOLETE_IND, NICKNAME, CREATED_USERID, PREVIOUS_SURNAME, INCOME_AMT, LANGUAGE_
REF_CODE, SURNAME, FIRST_NAME, DATE_OF_BIRTH, salutation, ID_VALUE, MARITAL_STA
US_CODE, LAST_UPDATED_TS, DATE_OF_DEATH, GENDER_CODE, CREATED_TS, ETHNICITY_COD
, LAST_UPDATED_USERID, NAME_SUFFIX_CODE, ID_Type_Code, INCOME_FREQ_CODE, MIDDLE
NAME, socialSecurityNum, InstanceID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
****************Instance: 797
16:12:28,488 DEBUG SQL:346 - select hibernate_sequence.nextval from dual
16:12:28,498 DEBUG SQL:346 - insert into Address (address1, address2, city, sta
e, zip, Person, InstanceID) values (?, ?, ?, ?, ?, ?, ?)
16:12:28,548 WARN JDBCExceptionReporter:71 - SQL Error: 2291, SQLState: 23000
16:12:28,548 ERROR JDBCExceptionReporter:72 - ORA-02291: integrity constraint (
IBERNATE.FK1ED033D4ACC03F9D) violated - parent key not found

16:12:28,548 WARN JDBCExceptionReporter:71 - SQL Error: 2291, SQLState: 23000
16:12:28,548 ERROR JDBCExceptionReporter:72 - ORA-02291: integrity constraint (
IBERNATE.FK1ED033D4ACC03F9D) violated - parent key not found

16:12:28,548 ERROR AbstractFlushingEventListener:299 - Could not synchronize da
abase state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC ba
ch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.
ava:69)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHel
er.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java
202)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:230

at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140

at org.hibernate.event.def.AbstractFlushingEventListener.performExecuti
ns(AbstractFlushingEventListener.java:296)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlu
hEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1007)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:354)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.jav
:106)
at com.everware.component.unittest.person.BaseRootDao.commitTransaction
Unknown Source)
at com.everware.component.unittest.person.BaseRootDao.saveOrUpdate(Unkn
wn Source)
at com.everware.component.unittest.person.BaseAddressDao.saveOrUpdate(U
known Source)
at com.everware.component.unittest.person.PersonTestCaseWrapper.createA
dress(Unknown Source)
at com.everware.component.unittest.person.PersonTestCaseWrapper.createP
rson(Unknown Source)
at com.everware.component.unittest.person.PersonTestCaseWrapper.createP
ople(Unknown Source)
at com.everware.component.unittest.person.PersonTestCaseWrapper.setUp(U
known Source)
at junit.framework.TestCase.runBare(TestCase.java:125)
at org.apache.cactus.internal.AbstractCactusTestCase.runBareServer(Abst
actCactusTestCase.java:149)
at org.apache.cactus.internal.server.AbstractWebTestCaller.doTest(Abstr
ctWebTestCaller.java:119)
at org.apache.cactus.internal.server.AbstractWebTestController.handleRe
uest_aroundBody0(AbstractWebTestController.java:93)
at org.apache.cactus.internal.server.AbstractWebTestController.handleRe
uest_aroundBody1$advice(AbstractWebTestController.java:224)
at org.apache.cactus.internal.server.AbstractWebTestController.handleRe
uest(AbstractWebTestController.java)
at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody2(Se
vletTestRedirector.java:101)
at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody3$ad
ice(ServletTestRedirector.java:224)
at org.apache.cactus.server.ServletTestRedirector.doPost(ServletTestRed
rector.java)
at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody0(Ser
letTestRedirector.java:72)
at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody1$adv
ce(ServletTestRedirector.java:224)
at org.apache.cactus.server.ServletTestRedirector.doGet(ServletTestRedi
ector.java)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.ru
(ServletStubImpl.java:996)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubI
pl.java:419)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubI
pl.java:315)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationActi
n.run(WebAppServletContext.java:6452)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(Authenticat
dSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java
118)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppS
rvletContext.java:3661)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestI
pl.java:2630)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)
Caused by: java.sql.BatchUpdateException: ORA-02291: integrity constraint (HIBE
NATE.FK1ED033D4ACC03F9D) violated - parent key not found

at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseE
ror.java:367)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePrepar
dStatement.java:8726)
at weblogic.jdbc.wrapper.PreparedStatement.executeBatch(PreparedStateme
t.java:137)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.ja
a:58)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java
195)
... 38 more
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC ba
ch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.
ava:69)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHel
er.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java
202)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:230

at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140

at org.hibernate.event.def.AbstractFlushingEventListener.performExecuti
ns(AbstractFlushingEventListener.java:296)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlu
hEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1007)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:354)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.jav
:106)
at com.everware.component.unittest.person.BaseRootDao.commitTransaction
Unknown Source)
at com.everware.component.unittest.person.BaseRootDao.saveOrUpdate(Unkn
wn Source)
at com.everware.component.unittest.person.BaseAddressDao.saveOrUpdate(U
known Source)
at com.everware.component.unittest.person.PersonTestCaseWrapper.createA
dress(Unknown Source)
at com.everware.component.unittest.person.PersonTestCaseWrapper.createP
rson(Unknown Source)
at com.everware.component.unittest.person.PersonTestCaseWrapper.createP
ople(Unknown Source)
at com.everware.component.unittest.person.PersonTestCaseWrapper.setUp(U
known Source)
at junit.framework.TestCase.runBare(TestCase.java:125)
at org.apache.cactus.internal.AbstractCactusTestCase.runBareServer(Abst
actCactusTestCase.java:149)
at org.apache.cactus.internal.server.AbstractWebTestCaller.doTest(Abstr
ctWebTestCaller.java:119)
at org.apache.cactus.internal.server.AbstractWebTestController.handleRe
uest_aroundBody0(AbstractWebTestController.java:93)
at org.apache.cactus.internal.server.AbstractWebTestController.handleRe
uest_aroundBody1$advice(AbstractWebTestController.java:224)
at org.apache.cactus.internal.server.AbstractWebTestController.handleRe
uest(AbstractWebTestController.java)
at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody2(Se
vletTestRedirector.java:101)
at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody3$ad
ice(ServletTestRedirector.java:224)
at org.apache.cactus.server.ServletTestRedirector.doPost(ServletTestRed
rector.java)
at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody0(Ser
letTestRedirector.java:72)
at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody1$adv
ce(ServletTestRedirector.java:224)
at org.apache.cactus.server.ServletTestRedirector.doGet(ServletTestRedi
ector.java)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.ru
(ServletStubImpl.java:996)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubI
pl.java:419)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubI
pl.java:315)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationActi
n.run(WebAppServletContext.java:6452)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(Authenticat
dSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java
118)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppS
rvletContext.java:3661)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestI
pl.java:2630)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)
Caused by: java.sql.BatchUpdateException: ORA-02291: integrity constraint (HIBE


Top
  
 
 Post subject:
PostPosted: Tue Feb 07, 2006 4:37 am 
Senior
Senior

Joined: Tue May 10, 2005 9:00 am
Posts: 125
Hello

check in you oracle database what constraint is HIBERNATE.FK1ED033D4ACC03F9D


Top
 Profile  
 
 Post subject: Checked the constraint
PostPosted: Wed Feb 08, 2006 12:14 pm 
Checked through Oracle Console. It is correctly mapped. It is a foreign key mapped to the InstanceID of the Person table.


Top
  
 
 Post subject: Hibernate Column Names
PostPosted: Wed Feb 08, 2006 12:17 pm 
Is this possibly related to te fact that both the PERSON table and ADDRESS table have PRIMARY KEY columns called INSTANCEID. The FOREIGN KEY in ADDRESS is called PERSON.


Top
  
 
 Post subject:
PostPosted: Thu Feb 09, 2006 2:32 am 
Senior
Senior

Joined: Tue May 10, 2005 9:00 am
Posts: 125
Quote:
It is a foreign key mapped to the InstanceID of the Person table


I suppose you mean it's the foreign key corresponding to your address -> person constraint. This then obviously mean your foreign key does not allow for null while, according to your code you didn't do a address.setPerson(somePerson) before saving data to database. Or you did set to a Person which is not in the database.

either update your db schema to allow null, either set a person before saving.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 09, 2006 2:38 am 
Senior
Senior

Joined: Tue May 10, 2005 9:00 am
Posts: 125
Sorry i just saw in your code
Quote:
address.setPerson(person);


So this is the second case, person is not in the database.

If this doesn't solve your problem, please provide the sql code of foreign key.


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