Tried the FK example in the tutorial. It works,
but now I need the FK to be another field. For
TABLE Employee(empID varchar(5), ...,
deptID varchar(5), ...,
TABLE Department(deptID varchar(5), ...,
I need deptID in Employee to refer to deptID in
Department. Followed the example in the
document ("Support Multiple Primary Keys"),
setJoinOn(Department._deptID), but still found
"Employee.deptID" set to
If I setBrokerGeneratedPrimaryKeys(false),
then "Employee.deptID" is set to NULL in the
For both Employee and Department, I
setPrimaryKeyField(...) to empID and deptID
respectively. I have tried with both AccessBroker
and RDBBroker but without success.
TIA for any help that can be provided.
From your example it appears as if you don't even need databaseIdentifier. deptId and empId appear to be sufficient. I would stop declaring the existance of databaseIdentifier and in the persistent map declare that the deptId and empId are the primary keys. Of course, this may mean you don't want to use broker generated primary keys. If that is the case, you'll have to setBrokerGeneratePrimaryKeys( false ) on the RDBPersistentAdapter instance associated with your persistent objects.
Did I understand correctly?
Yes, some of my cases require their own primary
keys. Since it is a greenfield project, having the
databaseIdentifier field doesn't bother me. I prefer
the simplicity and reliability of just extending
In any case, I did call
setBrokerGeneratedPrimaryKeys(false). I also
called setPrimaryKeyField(myPK). This works for
the normal non-FK cases. But if I try to set the
PK of the 2nd table (Dept-->deptID) as the FK of
the 1st table (Emp-->empID), the field
Emp-->deptID is set to NULL.
I won't die without if I can't use FK and aggregates.
But I foresee a number of cases where it would be
Anyway, thanks for all your help so far :)
You shouldn't have to call setPrimaryKeyField. Simply define a foreign relation in your persistence map. JGPL will automattically figure out which field in the related object is the primary key and thus determine the column name.
In the map for the employee object:
AttributeTypeColumn col = AttributeTypeColum.getForeignRelation( Deptartment.class, "deptId", _department );
A field is designated as a primary key in one of two ways. If your persistent definition is done with XML, simply identifying the primary key in the xml will be enough.
If you are defining your attribute map in code, there is a method on attribute type column that you should use.
In the map for a Department object:
AttributeTypeColumn col = AttributeTypeCoumn.getAttributeRelation( "deptId", _departmentId);
Thanks. It works now.
Log in to post a comment.
Sign up for the SourceForge newsletter:
You seem to have CSS turned off.
Please don't fill out this field.