I seem to be stuck at a point and dont know how to go about , would appreicate some help. I have read the forums but i could not find something to help me out
INDIVIDUAL
|
*
INDIV_APP *-----APPLICATION
|
*
ANSWERS
I have four tables A,B,C,D .
Table (INDIVIDUAL)
indivId(PK)
Table (APPLICATION)
appId(PK)
Table (INDIV_APP ) Link table
indivId(FK)
appId(FK)
Table ( ANSWERS )
answerId (generated by sequence)
indivId(FK) from link table
appId(FK) from link table
How do i generate the id part for table ANSWERS ? which consist of an id + composite keys ?
when i generate the way i have it it . I get a mpping exception telling me that i need to have a foreign key of appId and indivId , for the ANSWER
table
which i do agree. But how does one use the id generator and composite id
to co exist or should i be doing something totally different ?
Code:
<id name="id" column="ANSWER_ID" type="long">
<generator class="sequence">
<param name="sequence">ANS_SEQ</param>
</generator>
</id>
&&
<composite-id name="id" class="XYZId" unsaved-value="any">
<key-property name="individualId" access="field" column="INDIV_ID" length="10"/>
<key-property name="applicationId" access="field" column="APPLICATION_ID" length="10"/>
</composite-id>
to coexist ???
Hibernate version:3.05 Mapping documents:
Code:
[B] this is for table C[/B]
[code]
<hibernate-mapping package="common.orm.beans">
<class name="IndivAppXtable" table="INDIV_APPS">
<composite-id name="id" class="IndivAppXtableId1" unsaved-value="any">
<key-property name="individualId" access="field" column="INDIV_ID" length="10"/>
<key-property name="applicationId" access="field" column="APPLICATION_ID" length="10"/>
</composite-id>
<property name="artifactPrintDate" column="PRINT_DATE" type="date" not-null="true" />
<component name="rowHistory" class="RowHistory">
<property name="createdBy" column="CREATED_BY" type="java.lang.String" length="20" not-null="true" />
<property name="updatedBy" column="UPDATED_BY" type="java.lang.String" length="20" not-null="true" />
<property name="dateCreated" column="CREATION_DATE" type="java.util.Date" not-null="true" />
<property name="dateUpdated" column="UPDATE_DATE" type="java.util.Date" not-null="true" />
</component>
<many-to-one name="individual" column="INDIV_ID" class="Individual" insert="false" update="false" not-null="true"/>
<many-to-one name="application" column="APPLICATION_ID" class="Application" insert="false" update="false" not-null="true"/>
<set name="answers" inverse="true" cascade="save-update">
<key>
<column name="individualId"></column>
<column name="applicationId"></column>
</key>
<one-to-many class="Answer" />
</set>
<!--
<set name="indivs" inverse="true" cascade="all">
<key column="INDIV_ID"/>
<one-to-many class="Answer"/>
</set>
<set name="apps" inverse="true" cascade="save-update">
<key column="APPLICATION_ID"/>
<one-to-many class="Answer" />
</set>
-->
<!--
-->
</class>
</hibernate-mapping>
[/code]
[B] this is for table D [/B]
<?xml version="1.0" encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="common.orm.beans">
<class name="Answer" table="ANSWERS">
<!-- this takes care of the pk for this table -->
<id name="id" column="ANSWER_ID" type="long">
<generator class="sequence">
<param name="sequence">ANS_SEQ</param>
</generator>
</id>
<property name="answerFlg" column="ANSWER_FLG" type="string" not-null="true" />
<property name="answerDesc" column="ANSWER_DESC" type="string" />
<!-- component -->
<component name="rowHistory" class="RowHistory">
<property name="createdBy" column="CREATED_BY" type="java.lang.String" length="20" not-null="true" />
<property name="updatedBy" column="UPDATED_BY" type="java.lang.String" length="20" not-null="true" />
<property name="dateCreated" column="CREATION_DATE" type="java.util.Date" not-null="true" />
<property name="dateUpdated" column="UPDATE_DATE" type="java.util.Date" not-null="true" />
</component>
<many-to-one name="question" column="QUESTION_ID" class="Question" not-null="true" insert="false" update="false"/>
<many-to-one name="application" column="APPLICATION_ID" class="IndivAppXtable" not-null="true" insert="false" update="false"/>
<many-to-one name="individual" column="INDIV_ID" class="IndivAppXtable" not-null="true" insert="false" update="false"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
[code]
Foreign key (FK4FD94C2D61A73A30:ANSWERS [INDIV_ID])) must have same number of columns as the referenced primary key (INDIV_APPS [INDIV_ID,APPLICATION_ID])
at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:86)
at org.hibernate.mapping.ForeignKey.setReferencedTable(ForeignKey.java:51)
at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:976)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:921)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:999)
at util.HibernateSessionFactory.currentSession(HibernateSessionFactory.java:49)
at driver.Driver.main(Driver.java:41)
java.lang.NullPointerException
at util.HibernateSessionFactory.currentSession(HibernateSessionFactory.java:56)
at driver.Driver.main(Driver.java:41)
[code]
Name and version of the database you are using:
Oracle 9.2.0.1.0
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:[quote][/quote]