hi david,

in the reference-descriptor foreignkey you have to use a field defined in the same class-descriptor as the reference-descriptor.
the class-descriptor for state lacks the field 'countryStateId' as indicatet in the stack trace.


<class-descriptor
class="org.visres.contact.data.State"
table="States"
proxy="dynamic"
>
<field-descriptor
name="stateId"
column="StateId"
jdbc-type="INTEGER"
primarykey="true"
autoincrement="true"
sequence-name="GEN_StateId"
/>
<field-descriptor <<<<<<<<<<<<<<<<<<<<<<<<<<<<
name="countryStateId"
column="countryId"
jdbc-type="INTEGER"
/>
<field-descriptor
name="name"
column="Name"
jdbc-type="VARCHAR"
/>
<reference-descriptor
name="countryState"
class-ref="org.visres.contact.data.Country"
>
<foreignkey field-ref="countryStateId"/>
</reference-descriptor>
</class-descriptor>

hth
jakob

David Warnock wrote:

Hi,

I am having a problem with a simple relationship from N to 1 (ie a normal foreign key lookup to a parent table). I have tried looking at the OR guide on the website and at the broker unit tests but am very confused as I think I have copied the Artikle/ProductGroup example fully.

Thanks for your help.

My Unit Test error is:

Incorrect field reference "countryStateId" in org.apache.ojb.broker.metadata.ObjectReferenceDescriptor@1a28362[cascade delete=false,cascade retrieve=true,cascade store=false,is lazy=false,class of Items=class org.visres.contact.data.Country]
org.apache.ojb.broker.OJBRuntimeException: Incorrect field reference "countryStateId" in org.apache.ojb.broker.metadata.ObjectReferenceDescriptor@1a28362[cascade delete=false,cascade retrieve=true,cascade store=false,is lazy=false,class of Items=class org.visres.contact.data.Country]

It happens in this code

State sFind = null;
State sExample = new State();
sExample.setStateId( 1 );
Query query = new QueryByIdentity(sExample);
sFind = (State) broker.getObjectByQuery(query); // ERROR LINE

I have the following in my repository_user.xml (snipped extra fields)

<class-descriptor
class="org.visres.contact.data.Country"
table="Countries"
>
<field-descriptor
name="countryId"
column="CountryId"
jdbc-type="INTEGER"
primarykey="true"
autoincrement="true"
sequence-name="GEN_CountryId"
/>
<field-descriptor
name="name"
column="Name"
jdbc-type="VARCHAR"
/>
</class-descriptor>

<class-descriptor
class="org.visres.contact.data.State"
table="States"
proxy="dynamic"
>
<field-descriptor
name="stateId"
column="StateId"
jdbc-type="INTEGER"
primarykey="true"
autoincrement="true"
sequence-name="GEN_StateId"
/>
<field-descriptor
name="name"
column="Name"
jdbc-type="VARCHAR"
/>
<reference-descriptor
name="countryState"
class-ref="org.visres.contact.data.Country"
>
<foreignkey field-ref="countryStateId"/>
</reference-descriptor>
</class-descriptor>

And I have 2 classes (again extra fields snipped)

package org.visres.contact.data;

class Country implements java.io.Serializable {
private int countryId;
private String name;

public void setCountryId(int countryId) {
this.countryId = countryId;
}
public int getCountryId() {
return countryId;
}

public void setName(String s) {
name = s;
}
public String getName() {
return name;
}

}
===
package org.visres.contact.data;

class State implements java.io.Serializable {
private int stateId;
private String name;
private int countryStateId;
private Country countryState = null;

public void setStateId(int stateId) {
this.stateId = stateId;
}
public int getStateId() {
return stateId;
}

public void setName(String s) {
name = s;
}
public String getName() {
return name;
}

public void setCountryStateId(int countryStateId) {
this.countryStateId = countryStateId;
}
public int getCountryStateId() {
return countryStateId;
}

public void setCountryState(Country countryState) {
this.countryState = countryState;
}
public Country getCountryState() {
return countryState;
}
}


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

Reply via email to