hi bobby,

what version of ojb do you use ?

jakob

Bobby Lawrence schrieb:

Armin-
I can't use label as the key because to lookup a PI, I need the projectId and not the label.
My problem is, OJB is using the value for projectId as the value for BOTH foreign keys (projectId and fiscalYear). Its not using the fiscalYear value in the query lookup.
--Bobby


Armin Waibel wrote:

Bobby Lawrence wrote:

Armin - I have to.
I can a job table and a job class. The job table stores the project label. That is why it is listed as a primary key.
I have to set it up this way.
Can you help me with my problem?



First, the PK declaration in OJB is independent from the PK declaration in your DB (but avoid constraint violations ;-)).
OJB expects as FK fields in an object of a 1:n relation (PI) all PK fields of the main object (Project). In your case
PI:
fkFiscalYearId
fkLabelId


when Project has PK
fiscalYear
label

<collection-descriptor name="primaryInvestigators" element-class-ref="org.jlab.mis.services.mics.client.generated.PrimaryInvestigator" auto-retrieve="false">
<inverse-foreignkey field-ref="fkFiscalYearId" />
<inverse-foreignkey field-ref="fkLabelId" />
</collection-descriptor>


HTH,
Armin



Armin Waibel wrote:

Hi,

Project --1:n --> PrimaryInvestigator (PI)
PK fields for Project:
label
fiscalYears
why is 'id' not the PK in Project?

In PI FK are:
projectId
fiscalYear

projectId id not a PK in Project, you have to use a 'labelId'.

As a side-note, be really careful when using anonymous fields for fields other than 1:1 FK.

http://db.apache.org/ojb/docu/guides/advanced-technique.html#How+do+

regards,
Armin


Bobby Lawrence wrote:

Using the PersistenceBroker API...
I have a class that has a 1:n relationship -> a project can have many principal investigators.
The class descriptors look like this:


<class-descriptor class="org.jlab.mis.services.mics.client.generated.Project" table="projects">
<field-descriptor name="id" column="PROJECT_ID" jdbc-type="VARCHAR"/>
<field-descriptor name="label" column="REPO_CODE" jdbc-type="VARCHAR" primarykey="true" access="anonymous" />
<field-descriptor name="fiscalYear" column="FISCAL_YEAR" jdbc-type="VARCHAR" primarykey="true" />
<field-descriptor name="name" column="PROJECT_NAME" jdbc-type="VARCHAR" />
<collection-descriptor name="primaryInvestigators" element-class-ref="org.jlab.mis.services.mics.client.generated.PrimaryInvestigator" auto-retrieve="false">
<inverse-foreignkey field-ref="projectId" />
<inverse-foreignkey field-ref="fiscalYear" />
</collection-descriptor>
</class-descriptor>


<class-descriptor class="org.jlab.mis.services.mics.client.generated.PrimaryInvestigator" table="pis">
<field-descriptor name="id" column="PERSON_ID" jdbc-type="VARCHAR" primarykey="true"/>
<field-descriptor name="firstName" column="FIRSTNAME" jdbc-type="VARCHAR" />
<field-descriptor name="lastName" column="LASTNAME" jdbc-type="VARCHAR" />
<field-descriptor name="email" column="EMAIL" jdbc-type="VARCHAR" />
<field-descriptor name="fiscalYear" column="FISCAL_YEAR" jdbc-type="VARCHAR" access="anonymous" primarykey="true"/>
<field-descriptor name="projectId" column="PROJECT_ID" jdbc-type="VARCHAR" access="anonymous" />
</class-descriptor>


The problem is, whenever OJB tries to retrieve a collection of Primary Investigators, it never uses the correct value for the composite primary key.
The debugging output looks like this:


[org.apache.ojb.broker.accesslayer.JdbcAccessImpl] DEBUG: executeQuery : QueryByCriteria from class org.jlab.mis.services.mics.client.generated.PrimaryInvestigator where [projectId = 13179, fiscalYear = 13179]

As you can see, it is using the exact same value for the projectId and fiscalYear attributes.
What am I doing wrong?



--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to