File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Mapping document query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Mapping document query" Watch "Mapping document query" New topic
Author

Mapping document query

hariharakarthi Subramanian
Greenhorn

Joined: Aug 11, 2008
Posts: 11
I have table which has the below definition,

CREATE TABLE REPORTER.TRESERVE_FACTOR
(
MEASURE_ID NUMBER NOT NULL,
YEAR_NO NUMBER NOT NULL,
QUARTER_NO NUMBER(1,0) NOT NULL,
POOL_CD CHAR(8) NOT NULL,
COMPANY_NO CHAR(4) NOT NULL,
ANNUAL_STMT_LN_ID CHAR(3) NOT NULL,
CRNT_RESRV_FCTR_PC NUMBER(13,6) DEFAULT 0 NOT NULL,
MIN1_RESRV_FCTR_PC NUMBER(13,6) DEFAULT 0 NOT NULL,
MIN2_RESRV_FCTR_PC NUMBER(13,6) DEFAULT 0 NOT NULL,
MIN3_RESRV_FCTR_PC NUMBER(13,6) DEFAULT 0 NOT NULL,
MIN4_RESRV_FCTR_PC NUMBER(13,6) DEFAULT 0 NOT NULL,
UPDATE_TS DATE NOT NULL,
UPD_USER_ID CHAR(8) NOT NULL,
MIN5_RESRV_FCTR_PC NUMBER(13,6) DEFAULT 0 NOT NULL
)

PRIMARY KEY (MEASURE_ID,YEAR_NO,QUARTER_NO,POOL_CD,COMPANY_NO,ANNUAL_STMT_LN_ID)

I have created the entity class for the table TRESERVE_FACTOR using Netbeans. It created two POJOS,
TreserveFactor -- POJO for Table it has TreserveFactorPK as one of the type
TreserveFactorPK --- POJO class for Primarykeys of TRESERVE_FACTOR table

Now, I have problem in referring the primay keys in the mapping document.
Say, for example, I have a set created for this table.
Then, I can't define the property for primary key columns.
For, non primary key columns, I can define the proerty as follows,

<set name="treserveFactors" table="TRESERVE_FACTOR">
.
.
.
<property name ="crntResrvFctrPc" column="CRNT_RESRV_FCTR_PC"/>
</set>

But, for primary key columns I could not do it.

<set name="treserveFactors" table="TRESERVE_FACTOR">
<property name ="measureId" column="CRNT_RESRV_FCTR_PC"/>
.
.
</set>

If I define it like above, it is not working. I have tried other options like,

<property name ="treserveFactorPK " column="CRNT_RESRV_FCTR_PC"/>

Please advise.


Here, the property measureId is in TreserveFactorPK POJO Class..

Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

What exactly is the problem here? Is it mapping a collection to class with a compound primary key? In that case, you just treat the compound key as the primary key in the mappings.

-Cameron McKenzie
hariharakarthi Subramanian
Greenhorn

Joined: Aug 11, 2008
Posts: 11
Thanks for your replay.

Given below is my mapping file class,

<class name="icp.entity.TannualStmtLine" table="TANNUAL_STMT_LINE">
<id column="ANNUAL_STMT_LN_ID" name="annualStmtLnId" type="string">
<generator class="assigned"/>
</id>
<property name="annualStmtLnNm" type="string">
<column length="30" name="ANNUAL_STMT_LN_NM" not-null="true"/>
</property>
<property name="updateTs" type="timestamp">
<column length="45" name="UPDATE_TS" not-null="true"/>
</property>
<property name="updUserId" type="string">
<column length="8" name="UPD_USER_ID" not-null="true"/>
</property>
<property name="exceptionIn" type="char">
<column length="1" name="EXCEPTION_IN" not-null="true"/>
</property>
<property name="ovAnnlStmtLnId" type="string">
<column length="3" name="OV_ANNL_STMT_LN_ID" not-null="true"/>
</property>
<set name="treserveFactors" table="TRESERVE_FACTOR">
<key column="ANNUAL_STMT_LN_ID"/>
<composite-element class="icp.entity.TreserveFactor">
<parent name="icp.entity.TannualStmtLine"/>
<property name ="treserveFactorPK" column="MEASURE_ID"/>
<property name ="treserveFactorPK" column="YEAR_NO"/>
<property name ="treserveFactorPK" column="QUARTER_NO"/>
<property name ="treserveFactorPK" column="POOL_CD"/>
<property name ="treserveFactorPK" column="COMPANY_NO"/>
<property name ="crntResrvFctrPc" column="CRNT_RESRV_FCTR_PC"/>
<property name ="min1ResrvFctrPc" column="MIN1_RESRV_FCTR_PC"/>
<property name ="min2ResrvFctrPc" column="MIN2_RESRV_FCTR_PC"/>
<property name ="min3ResrvFctrPc" column="MIN3_RESRV_FCTR_PC"/>
<property name ="min4ResrvFctrPc" column="MIN4_RESRV_FCTR_PC"/>
<property name ="updateTs" column="UPDATE_TS"/>
<property name ="updUserId" column="UPD_USER_ID"/>
<property name ="min5ResrvFctrPc" column="MIN5_RESRV_FCTR_PC"/>
</composite-element>
</set>
</class>

I am trying to add a collection of TRESERVE_FACTOR table in the TannualStmtLine java class.

I use the below query to get the data from the database,

<sql-query name="findReserveFactors"><![CDATA[
SELECT TannualStmtLine.*,TreserveFactor.*
FROM REPORTER.TANNUAL_STMT_LINE TannualStmtLine
right outer join REPORTER.TRESERVE_FACTOR TreserveFactor
on TannualStmtLine.ANNUAL_STMT_LN_ID = TreserveFactor.ANNUAL_STMT_LN_ID
AND TreserveFactor.YEAR_NO=:year
AND TreserveFactor.QUARTER_NO=:quarter
AND TreserveFactor.MEASURE_ID=:measureid
AND TreserveFactor.COMPANY_NO=:comp
where
TannualStmtLine.ANNUAL_STMT_LN_ID ><> '310'
order by TannualStmtLine.ANNUAL_STMT_LN_ID]]>
<return alias ="TannualStmtLine" class="icp.entity.TannualStmtLine"/>

</sql-query>

I am completely missing something here. But, I don't what is it.

Below is the set,

<set name="treserveFactors" table="TRESERVE_FACTOR">
<key column="ANNUAL_STMT_LN_ID"/>
<composite-element class="icp.entity.TreserveFactor">
<parent name="icp.entity.TannualStmtLine"/>
<property name ="treserveFactorPK" column="MEASURE_ID"/>
<property name ="treserveFactorPK" column="YEAR_NO"/>
<property name ="treserveFactorPK" column="QUARTER_NO"/>
<property name ="treserveFactorPK" column="POOL_CD"/>
<property name ="treserveFactorPK" column="COMPANY_NO"/>
<property name ="crntResrvFctrPc" column="CRNT_RESRV_FCTR_PC"/>
<property name ="min1ResrvFctrPc" column="MIN1_RESRV_FCTR_PC"/>
<property name ="min2ResrvFctrPc" column="MIN2_RESRV_FCTR_PC"/>
<property name ="min3ResrvFctrPc" column="MIN3_RESRV_FCTR_PC"/>
<property name ="min4ResrvFctrPc" column="MIN4_RESRV_FCTR_PC"/>
<property name ="updateTs" column="UPDATE_TS"/>
<property name ="updUserId" column="UPD_USER_ID"/>
<property name ="min5ResrvFctrPc" column="MIN5_RESRV_FCTR_PC"/>
</composite-element>
</set>

I have given the parent tag in the set because ANNUAL_STMT_LN_ID column is a primary key on the table TANNUAL_STMT_LINE. I am trying to do the mapping for the remaining columns of the table TRESERVE_FACTOR.

TRESERVE_FACTOR table has the following primay keys,
<property name ="treserveFactorPK" column="MEASURE_ID"/>
<property name ="treserveFactorPK" column="YEAR_NO"/>
<property name ="treserveFactorPK" column="QUARTER_NO"/>
<property name ="treserveFactorPK" column="POOL_CD"/>
<property name ="treserveFactorPK" column="COMPANY_NO"/>

I have given the name of the property as treserveFactorPK. The reason is when I created a entitiy POJO for TRESERVE_FACTOR, it created two java classes.
TreserveFactorPK - Contains only all the primay keys of table TRESERVE_FACTOR.
TreserveFactor - Contains TreserveFactorPK as one of the element and all non-primay keys of TRESERVE_FACTOR.

My problem is how to define the property element within Composite-element. Say for example how to define the MEASURE_ID field, I have tried the below options, all are failed,

<property name ="measureId" column="MEASURE_ID"/>
<property name ="treserveFactorPK" column="MEASURE_ID"/>
<property name ="treserveFactorPK.measureId" column="MEASURE_ID"/>

error:
MeasureId not defined in class TreserveFactor

Can anyone tell me how to define this? Sorry, I know it may be insane to you.. But, I struck on this by more than two weeks now..........help is appericated..






 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Mapping document query
 
Similar Threads
Foreign key must have same number of columns as the referenced primary key
one-to-many mapping with table having no primay key
Hibernate Mapping help required
Set- Key Mapping issue with nested-composite-element
Mapping Problem in Hibernate