-->
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.  [ 12 posts ] 
Author Message
 Post subject: one-to-many -- ORA-02291: integrity constraint
PostPosted: Fri Feb 24, 2006 1:20 pm 
Beginner
Beginner

Joined: Fri Feb 24, 2006 12:52 pm
Posts: 30
Hibernate version:
2.1.8

Mapping documents:
<?xml version="1.0" encoding="UTF-8"?>

<!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.bmc.idm.cmplmgr.bo._common.ColumnImpl"
table="A_COLUMN">

<cache usage="nonstrict-read-write"/>

<!-- Primary key -->
<id name="id"
column="ID"
type="long"
access="property"
unsaved-value="-1">
<generator class="native"/>
</id>

<property name="resultSetEntryID" column="RESULT_SET_ENTRY_ID" type="long"/>


<component name="databaseColumn"
class="com.bmc.idm.cmplmgr.bo._common.databasecolumn.DatabaseColumnImpl">
<property name="name"/>

<property name="fieldType"
column="FIELD_TYPE"
type="com.bmc.idm.cmplmgr.bo._common.FieldTypeUserType"/>
</component>

<component name="resultSetMetaData"
class="com.bmc.idm.cmplmgr.bo._common.resultsetmetadata.ResultSetMetaDataImpl">
<property name="responsiveField"
type="boolean"
column="RESPONSIVE_FIELD">
</property>

<property name="dispalyField"
type="boolean"
column="DISPLAY_FIELD">
</property>

<property name="viewerFilter"
type="boolean"
column="VIEWER_FILTER">
</property>

<property name="displayFilter"
type="boolean"
column="DISPLAY_FILTER">
</property>

<property name="description"/>

</component>
</class>
</hibernate-mapping>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<?xml version="1.0" encoding="UTF-8"?>

<!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.bmc.idm.cmplmgr.bo._common.result.ResultsetEntryImpl"
table="A_RESULT_SET_ENTRY">

<cache usage="nonstrict-read-write"/>

<!-- Primary key -->
<id name="id"
column="ID"
type="long"
access="property"
unsaved-value="-1">
<generator class="native"/>
</id>


<property name="name"/>
<property name="approvedExceptionKeyField" type="boolean" column="APPROVED_EXCEPTION_KEY_FIELD"/>

<!-- A collection of columns associated with this resultSetEntry -->
<bag name="columns" table="A_COLUMN" cascade="all-delete-orphan" lazy="true">
<key column="RESULT_SET_ENTRY_ID"/>
<one-to-many
class="com.bmc.idm.cmplmgr.bo._common.ColumnImpl"/>
</bag>



</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
ResultsetEntry resultsetEntry = new ResultsetEntryImpl();
resultsetEntry.setName("ny name is result set " + new Date().toString());
resultsetEntry.setApprovedExceptionKeyField(true);
List<Column> columnList = new ArrayList<Column>();
Column column = new ColumnImpl();
DatabaseColumn databaseColumn = new DatabaseColumnImpl();
databaseColumn.setFieldType(FieldType.ftInteger);
databaseColumn.setName("db col");
column.setDatabaseColumn(databaseColumn);
ResultSetMetaData resultSetMetaData = new ResultSetMetaDataImpl();
resultSetMetaData.setDescription("description");
resultSetMetaData.setDispalyField(true);
resultSetMetaData.setDisplayFilter(false);
resultSetMetaData.setResponsiveField(true);
resultSetMetaData.setViewerFilter(false);
column.setResultSetMetaData(resultSetMetaData);
columnList.add(column);
resultsetEntry.setColumns(columnList);
Session s = OrmHelper.getSession();
Transaction transaction = s.beginTransaction();
s.save(resultsetEntry);
transaction.commit();
s.close();

Full stack trace of any exception that occurs:
################### Start to init the cmpl_mgr_backend Logger ###################
2006-02-24 19:08:02,402 ERROR [main] net.sf.hibernate.util.JDBCExceptionReporter - ORA-02291: integrity constraint (ABALDERM.FK786E2914B486C467) violated - parent key not found

2006-02-24 19:08:02,402 ERROR [main] net.sf.hibernate.util.JDBCExceptionReporter - ORA-02291: integrity constraint (ABALDERM.FK786E2914B486C467) violated - parent key not found

2006-02-24 19:08:02,402 ERROR [main] net.sf.hibernate.util.JDBCExceptionReporter - ORA-02291: integrity constraint (ABALDERM.FK786E2914B486C467) violated - parent key not found

2006-02-24 19:08:02,402 ERROR [main] net.sf.hibernate.util.JDBCExceptionReporter - ORA-02291: integrity constraint (ABALDERM.FK786E2914B486C467) violated - parent key not found

2006-02-24 19:08:02,418 ERROR [main] net.sf.hibernate.impl.SessionImpl - Could not synchronize database state with session
net.sf.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at net.sf.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:73)
at net.sf.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
at net.sf.hibernate.impl.BatcherImpl.convert(BatcherImpl.java:328)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:135)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2438)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2392)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2261)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at com.bmc.idm.cmplmgr.bo.backend.query.QueryTest.resultSetEntrySaveAndFetch(QueryTest.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:485)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:398)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:625)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:88)
at org.testng.TestRunner.privateRun(TestRunner.java:614)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:221)
at org.testng.SuiteRunner.run(SuiteRunner.java:147)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:86)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:123)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:86)
Caused by: java.sql.BatchUpdateException: ORA-02291: integrity constraint (ABALDERM.FK786E2914B486C467) violated - parent key not found

at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:459)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:4210)
at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:294)
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:128)
... 24 more

===============================================
com.bmc.idm.cmplmgr.bo.backend.query.QueryTest
Total tests run: 1, Failures: 1, Skips: 0
===============================================


Process finished with exit code 0


Name and version of the database you are using:
<property name="hibernateProperties">
<props>
<!--<prop key="query.substitutions">true 1, false 0, yes 'Y', no 'N'</prop>-->
<prop key="hibernate.dialect">net.sf.hibernate.dialect.Oracle9Dialect</prop>
<prop key="jdbc.batch_size">0</prop>
<prop key="jdbc.V8Compatible">true</prop>
<prop key="jdbc.use_streams_for_binary">true</prop>
<prop key="max_fetch_depth">1</prop>
<prop key="cache.provider_class">net.sf.hibernate.cache.EhCacheProvider</prop>
<prop key="cache.use_query_cache">true</prop>
<prop key="hibernate.show_sql">true</prop>
</props>

The generated SQL (show_sql=true):
Hibernate: select hibernate_sequence.nextval from dual
Hibernate: select hibernate_sequence.nextval from dual
Hibernate: insert into A_RESULT_SET_ENTRY (name, APPROVED_EXCEPTION_KEY_FIELD, ID) values (?, ?, ?)
Hibernate: insert into A_COLUMN (RESULT_SET_ENTRY_ID, name, FIELD_TYPE, RESPONSIVE_FIELD, DISPLAY_FIELD, VIEWER_FILTER, DISPLAY_FILTER, description, ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?)

Debug level Hibernate log excerpt:[/b]

_________________
Avishay Balderman


Top
 Profile  
 
 Post subject: Here is hibernate log:
PostPosted: Fri Feb 24, 2006 2:13 pm 
Beginner
Beginner

Joined: Fri Feb 24, 2006 12:52 pm
Posts: 30
You can see that there is mismatch of the keys:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2006-02-24 20:03:59,641 DEBUG [main] net.sf.hibernate.impl.BatcherImpl - preparing statement
2006-02-24 20:03:59,641 DEBUG [main] net.sf.hibernate.persister.EntityPersister - Dehydrating entity: [com.bmc.idm.cmplmgr.bo._common.result.ResultsetEntryImpl#1]
2006-02-24 20:03:59,641 DEBUG [main] net.sf.hibernate.type.StringType - binding 'ny name is result set Fri Feb 24 20:03:46 EET 2006' to parameter: 1
2006-02-24 20:03:59,641 DEBUG [main] net.sf.hibernate.type.BooleanType - binding 'true' to parameter: 2
2006-02-24 20:03:59,641 DEBUG [main] net.sf.hibernate.type.LongType - binding '1' to parameter: 3
2006-02-24 20:03:59,641 DEBUG [main] net.sf.hibernate.impl.BatcherImpl - Adding to batch
2006-02-24 20:03:59,656 DEBUG [main] net.sf.hibernate.persister.EntityPersister - Inserting entity: [com.bmc.idm.cmplmgr.bo._common.ColumnImpl#2]
2006-02-24 20:03:59,656 DEBUG [main] net.sf.hibernate.impl.BatcherImpl - Executing batch size: 1
2006-02-24 20:03:59,688 DEBUG [main] net.sf.hibernate.impl.BatcherImpl - success of batch update unknown: 0
2006-02-24 20:03:59,688 DEBUG [main] net.sf.hibernate.impl.BatcherImpl - done closing: 0 open PreparedStatements, 0 open ResultSets
2006-02-24 20:03:59,688 DEBUG [main] net.sf.hibernate.impl.BatcherImpl - closing statement
2006-02-24 20:03:59,703 DEBUG [main] net.sf.hibernate.impl.BatcherImpl - about to open: 0 open PreparedStatements, 0 open ResultSets
2006-02-24 20:03:59,703 DEBUG [main] net.sf.hibernate.SQL - insert into A_COLUMN (RESULT_SET_ENTRY_ID, name, FIELD_TYPE, RESPONSIVE_FIELD, DISPLAY_FIELD, VIEWER_FILTER, DISPLAY_FILTER, description, ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?)
2006-02-24 20:03:59,703 DEBUG [main] net.sf.hibernate.impl.BatcherImpl - preparing statement
2006-02-24 20:03:59,703 DEBUG [main] net.sf.hibernate.persister.EntityPersister - Dehydrating entity: [com.bmc.idm.cmplmgr.bo._common.ColumnImpl#2]
2006-02-24 20:03:59,703 DEBUG [main] net.sf.hibernate.type.LongType - binding '0' to parameter: 1
2006-02-24 20:03:59,703 DEBUG [main] net.sf.hibernate.type.StringType - binding 'db col' to parameter: 2
2006-02-24 20:03:59,703 DEBUG [main] net.sf.hibernate.type.BooleanType - binding 'true' to parameter: 4
2006-02-24 20:03:59,703 DEBUG [main] net.sf.hibernate.type.BooleanType - binding 'true' to parameter: 5
2006-02-24 20:03:59,703 DEBUG [main] net.sf.hibernate.type.BooleanType - binding 'false' to parameter: 6
2006-02-24 20:03:59,703 DEBUG [main] net.sf.hibernate.type.BooleanType - binding 'false' to parameter: 7
2006-02-24 20:03:59,703 DEBUG [main] net.sf.hibernate.type.StringType - binding 'description' to parameter: 8
2006-02-24 20:03:59,703 DEBUG [main] net.sf.hibernate.type.LongType - binding '2' to parameter: 9
2006-02-24 20:03:59,703 DEBUG [main] net.sf.hibernate.impl.BatcherImpl - Adding to batch
2006-02-24 20:03:59,703 DEBUG [main] net.sf.hibernate.impl.BatcherImpl - Executing batch size: 1
2006-02-24 20:03:59,781 DEBUG [main] net.sf.hibernate.util.JDBCExceptionReporter - SQL Exception
java.sql.BatchUpdateException: ORA-02291: integrity constraint (ABALDERM.FK786E2914B486C467) violated - parent key not found

at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:459)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:4210)
at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:294)
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:128)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2438)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2392)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2261)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at com.bmc.idm.cmplmgr.bo.backend.query.QueryTest.resultSetEntrySaveAndFetch(QueryTest.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:485)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:398)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:625)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:88)
at org.testng.TestRunner.privateRun(TestRunner.java:614)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:221)
at org.testng.SuiteRunner.run(SuiteRunner.java:147)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:86)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:123)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:86)
2006-02-24 20:03:59,781 WARN [main] net.sf.hibernate.util.JDBCExceptionReporter - SQL Error: 2291, SQLState: 23000
2006-02-24 20:03:59,781 ERROR [main] net.sf.hibernate.util.JDBCExceptionReporter - ORA-02291: integrity constraint (ABALDERM.FK786E2914B486C467) violated - parent key not found

2006-02-24 20:03:59,797 WARN [main] net.sf.hibernate.util.JDBCExceptionReporter - SQL Error: 2291, SQLState: 23000
2006-02-24 20:03:59,797 ERROR [main] net.sf.hibernate.util.JDBCExceptionReporter - ORA-02291: integrity constraint (ABALDERM.FK786E2914B486C467) violated - parent key not found

2006-02-24 20:03:59,797 DEBUG [main] net.sf.hibernate.impl.BatcherImpl - done closing: 0 open PreparedStatements, 0 open ResultSets
2006-02-24 20:03:59,797 DEBUG [main] net.sf.hibernate.impl.BatcherImpl - closing statement
2006-02-24 20:03:59,813 DEBUG [main] net.sf.hibernate.util.JDBCExceptionReporter - Could not execute JDBC batch update
java.sql.BatchUpdateException: ORA-02291: integrity constraint (ABALDERM.FK786E2914B486C467) violated - parent key not found

at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:459)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:4210)
at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:294)
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:128)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2438)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2392)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2261)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at com.bmc.idm.cmplmgr.bo.backend.query.QueryTest.resultSetEntrySaveAndFetch(QueryTest.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:485)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:398)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:625)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:88)
at org.testng.TestRunner.privateRun(TestRunner.java:614)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:221)
at org.testng.SuiteRunner.run(SuiteRunner.java:147)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:86)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:123)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:86)
2006-02-24 20:03:59,813 WARN [main] net.sf.hibernate.util.JDBCExceptionReporter - SQL Error: 2291, SQLState: 23000
2006-02-24 20:03:59,813 ERROR [main] net.sf.hibernate.util.JDBCExceptionReporter - ORA-02291: integrity constraint (ABALDERM.FK786E2914B486C467) violated - parent key not found

2006-02-24 20:03:59,813 WARN [main] net.sf.hibernate.util.JDBCExceptionReporter - SQL Error: 2291, SQLState: 23000
2006-02-24 20:03:59,813 ERROR [main] net.sf.hibernate.util.JDBCExceptionReporter - ORA-02291: integrity constraint (ABALDERM.FK786E2914B486C467) violated - parent key not found

2006-02-24 20:03:59,828 ERROR [main] net.sf.hibernate.impl.SessionImpl - Could not synchronize database state with session

_________________
Avishay Balderman


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 24, 2006 2:39 pm 
Expert
Expert

Joined: Mon Jan 09, 2006 5:01 pm
Posts: 311
Location: Sacramento, CA
balderman,

By way of suggestion here: Summarize your problem in the beginning, pointing out your exact scenario then list the files that support it -- it may be too much trouble for folks to a) analyze your data, b) figure what might be the problem and possibly guess wrong and c) make recommendation based on false assumptions... too much quess work.

just a thought.


Top
 Profile  
 
 Post subject: Problem description
PostPosted: Fri Feb 24, 2006 3:35 pm 
Beginner
Beginner

Joined: Fri Feb 24, 2006 12:52 pm
Posts: 30
I have 2 POJO's.
The first holds a collection of the second.
When I fill the POJO's with data and do seesion.save() I gor the violation constraint error.
Avishay

_________________
Avishay Balderman


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 24, 2006 4:42 pm 
Expert
Expert

Joined: Mon Jan 09, 2006 5:01 pm
Posts: 311
Location: Sacramento, CA
Looks like:

ResultsetEntryImpl (1) to (Many) ColumnImpl

so in ResultsetEntryImpl.java make sure there is a List defined, ie:

List columns=null;
with get and sets for the list - ie List getColumns() and setColumns(List...).

and in

ColumnImpl.java make sure there is a single:

ResultsetEntryImpl resultSetEntry=null;
with its gets and sets.

ResultsetEntryImpl getResultSetEntry()...
void setResultSetEntry(ResultsetEntryImpl )

Don't refer to them by ID's (w/long) ...as you are currently doing. use Objects...

I think that should get you going.

_________________
-JT

If you find my replies helpful, please rate by clicking 'Y' on them. I appreciate it.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 25, 2006 2:00 am 
Beginner
Beginner

Joined: Fri Feb 24, 2006 12:52 pm
Posts: 30
It is true that the relationships are:
ResultsetEntryImpl (1) to (Many) ColumnImpl
and since that the POJO's looks like this:

Code:
public class ResultsetEntryImpl
{
     ....
     List<ColumnImpl > columnList;
     .....   
}

public class ColumnImpl
{
     ....
     
     // Nothing about ResultsetEntryImpl
     // since it does not need to know that it is hold in a collection in th
     // class ResultsetEntryImpl
     
     .....   
}


This is how I understand <one-to-many>

Thanks
Avishay

_________________
Avishay Balderman


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 25, 2006 11:31 am 
Expert
Expert

Joined: Mon Jan 09, 2006 5:01 pm
Posts: 311
Location: Sacramento, CA
that is a many-to-one unidirectional relationship - OK...
if you are still having problems, then post your java code that is used to create the objects and calling save.

_________________
-JT

If you find my replies helpful, please rate by clicking 'Y' on them. I appreciate it.


Top
 Profile  
 
 Post subject: The code:
PostPosted: Sat Feb 25, 2006 12:26 pm 
Beginner
Beginner

Joined: Fri Feb 24, 2006 12:52 pm
Posts: 30
Code:
ResultsetEntry resultsetEntry = new ResultsetEntryImpl();
resultsetEntry.setName("ny name is result set " + new Date().toString());
resultsetEntry.setApprovedExceptionKeyField(true);
List<Column> columnList = new ArrayList<Column>();
Column column = new ColumnImpl();
DatabaseColumn databaseColumn = new DatabaseColumnImpl();
databaseColumn.setFieldType(FieldType.ftInteger);
databaseColumn.setName("db col");
column.setDatabaseColumn(databaseColumn);
ResultSetMetaData resultSetMetaData = new ResultSetMetaDataImpl();
resultSetMetaData.setDescription("description");
resultSetMetaData.setDispalyField(true);
resultSetMetaData.setDisplayFilter(false);
resultSetMetaData.setResponsiveField(true);
resultSetMetaData.setViewerFilter(false);
column.setResultSetMetaData(resultSetMetaData);
columnList.add(column);
resultsetEntry.setColumns(columnList);
Session s = OrmHelper.getSession();
Transaction transaction = s.beginTransaction();
s.save(resultsetEntry);
transaction.commit();
s.close();

_________________
Avishay Balderman


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 25, 2006 12:52 pm 
Expert
Expert

Joined: Mon Jan 09, 2006 5:01 pm
Posts: 311
Location: Sacramento, CA
run this to determine information about which referential constraint it doesn't like:

generally:
Code:
select * from all_constraints where constraint_type = 'R'


I think this may work, but you may have to fiddle with it:
Code:
SELECT T.owner AS CHILD_OWNER,
T.table_name AS CHILD_TABLE,
T.constraint_name AS FOREIGN_KEY_NAME,
R.owner AS PARENT_OWNER,
R.table_name AS PARENT_TABLE,
R.constraint_name AS PARENT_CONSTRAINT
FROM all_constraints T, all_constraints R
WHERE T.r_constraint_name = R.constraint_name
AND T.r_owner = R.owner
AND T.constraint_type='R'
AND R.owner = 'ABALDERM'
AND T.owner = 'ABALDERM'
and T.constraint_name='FK786E2914B486C467';

_________________
-JT

If you find my replies helpful, please rate by clicking 'Y' on them. I appreciate it.


Top
 Profile  
 
 Post subject: Schema is generated from the hbm's
PostPosted: Sat Feb 25, 2006 12:58 pm 
Beginner
Beginner

Joined: Fri Feb 24, 2006 12:52 pm
Posts: 30
Hi
Since the schema is generated from the hbm's there is no point to manipulate the DB via SQL. I must find the correct mapping.
Avishay

_________________
Avishay Balderman


Top
 Profile  
 
 Post subject: The solution
PostPosted: Sun Feb 26, 2006 3:16 am 
Beginner
Beginner

Joined: Fri Feb 24, 2006 12:52 pm
Posts: 30
Hi
here is the solution:
Hibernate wiil generate the field RESULT_SET_ENTRY_COLUMN_ID in the table A_COLUMN.
So the connection between the tables is:
A_RESULT_SET_ENTRY.ID --> A_COLUMN.RESULT_SET_ENTRY_COLUMN_ID


<class name="com.bmc.idm.cmplmgr.bo._common.result.ResultsetEntryImpl"
table="A_RESULT_SET_ENTRY">

<cache usage="nonstrict-read-write"/>

<!-- Primary key -->
<id name="id"
column="ID"
type="long"
access="property"
unsaved-value="-1">
<generator class="native"/>
</id>


<property name="name"/>
<property name="approvedExceptionKeyField" type="boolean" column="APPROVED_EXCEPTION_KEY_FIELD"/>

<!-- A collection of columns associated with this resultSetEntry -->
<bag name="columns" table="A_COLUMN" cascade="save-update" lazy="true">
<key column="RESULT_SET_ENTRY_COLUMN_ID"/>
<one-to-many
class="com.bmc.idm.cmplmgr.bo._common.ColumnImpl"/>
</bag>


</class>

Avishay

_________________
Avishay Balderman


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 27, 2006 2:32 pm 
Expert
Expert

Joined: Mon Jan 09, 2006 5:01 pm
Posts: 311
Location: Sacramento, CA
Glad to hear its working -
I hope that helped...

_________________
-JT

If you find my replies helpful, please rate by clicking 'Y' on them. I appreciate it.


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