James Treleaven <jametre..noreo.on.ca> wrote:
> To be specific (pedantic?), my db includes two tables 'team' and
> 'project' with primary keys 'team_id' and 'project_id', respectively.
> What I would like right now is to be able to call getProject_id() from
> my Team objects, but when I used the modeler to create my DataObjects it
> did not generate a getProject_id() method for the Team class.
> Similarly, no getTeam_id() method exists in the Team class either and I
> will probably need access to it as well at some point in the near future.
Use something like this in your data objects.
public Number primaryKey()
{
String primaryKeysString = null;
Map pkAttributes = this.getObjectId().getIdSnapshot();
if (1 != pkAttributes.size()) throw new
CayenneRuntimeException("multi-field primary key found.");
Iterator pkIterator = pkAttributes.keySet().iterator();
String primaryKeyName = (String) pkIterator.next();
Number primaryKeyValue = (Number)pkAttributes.get(primaryKeyName);
return primaryKeyValue;
}
This archive was generated by hypermail 2.0.0 : Thu Nov 27 2003 - 16:02:37 EST