Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Mapping document query

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..

 
author and cow tipper
Posts: 5000
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..






 
"How many licks ..." - I think all of this dog's research starts with these words. Tasty tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic