I am having a problem with an 1:n relationship.
Imagine we have an relationship between user and location so that location can have multiple users. One user is bound to one location.
The classes look like this:
*********************
* USER - Class
*********************
public class User {
private String userid = null;
private String firstname = null;
private String lastname = null;
// Reference to Location private String locationkey = null; private Location refTo_location = null;
// all the Getter/Setter - methods
}
*********************
* LOCATION- Class
*********************
public class Buch_Location {
private String locationid = null;
private String name = null;
// Reference to Users
private Vector colOf_user = new Vector();//Getter/Setter }
Keep in mind that the IDs are all String-Values. They should be converted within OJB !!!!
******************************************************
******************************************************
*********************
* USER - Mapping
*********************
<class-descriptor
class="User"
table="USER"
>
<field-descriptor
name="userid"
column="USERID"
jdbc-type="INTEGER"
primarykey="true"
autoincrement="true"
conversion="ojb.conversion.String2IntFieldConversion"
/>
<field-descriptor
name="firstname"
column="FIRSTNAME"
jdbc-type="VARCHAR"
/>
<field-descriptor
name="lastname"
column="LASTNAME"
jdbc-type="VARCHAR"
/> <field-descriptor
name="locationkey"
column="LOCATIONKEY"
jdbc-type="INTEGER"
conversion="ojb.conversion.String2IntFieldConversion"
/> <reference-descriptor
name="refTo_location"
class-ref="Location"
auto-retrieve="true"
>
<foreignkey field-ref="locationkey"/>
</reference-descriptor>
</class-descriptor>
*********************
* LOCATION- Mapping
*********************
<class-descriptor
class="Location"
table="LOCATION"
>
<field-descriptor
name="locationid"
column="LOCATIONID"
jdbc-type="INTEGER"
primarykey="true"
autoincrement="true"
conversion="ojb.conversion.String2IntFieldConversion"
/>
<field-descriptor
name="name"
column="NAME"
jdbc-type="VARCHAR"
/>
<collection-descriptor
name="colOf_user"
element-class-ref="User"
orderby="userid"
sort="DESC"
>
<inverse-foreignkey field-ref="locationkey"/>
</collection-descriptor>
</class-descriptor>
******************************************************
******************************************************
now the String2IntFieldConversion-Class is just like this:
...
public Object javaToSql(Object arg0) throws ConversionException {
return Integer.valueOf((String) arg0);
} public Object sqlToJava(Object arg0) throws ConversionException {
return String.valueOf( (Integer) arg0);
}
...
******************************************************
******************************************************Now the Problem is that OJB can't load the User using the conversion-class. If I don't use the conversion and use integers for the IDs instead of Strings it works fine.
It also works fine if you use an automatic m:n - mapping with an "indirection-table" -> No problem for OJB to handle this using the conversion.
Can somebody tell me what I am doing wrong ?
BTW the IDs of the DB Tables (mySQL) are "bigint".
Thanks for your help,
Ralf Geiger
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
