Hi,

On Jan 7, 2010, at 2:57 PM, KARR, DAVID (ATTCINW) wrote:

Let's say that I have an entity called "Category" with a "name" field.
It's mapped to a table called "CATEGORY" and the "NAME" column.  This
part works fine.

Now I'm trying to add a mapping for a secondary table, called
"CATEGORY_ES" which has rows corresponding to many of the rows in
"CATEGORY", but not all of them.  This table also has a "NAME" column,
but it's in Spanish, instead of English.

I originally thought I would map CATEGORY_ES as a "secondary-table", but
that appears to not be possible, as there are rows in "CATEGORY" that
don't have corresponding rows in "CATEGORY_ES".  When I do a query for
rows that don't have a row in CATEGORY_ES, the query fails.

I originally had a "name" field, so I was thinking I would make that a
transient field, and also have "nameEN" and "nameES", and do a
translation after properties are set to determine what "name" is.

I might have to make the "Category" entity have a one-to-one field
called "categoryES", of type "CategoryES" (mapped to the obvious table) which will either be set or not. Does this look like the best way to do
this?

Yes. A OneToOne with cardinality 0..1 sounds like it exactly matches your description. The main requirement is that there is a column in the CATEGORY table that is the target of a foreign key in the CATEGORY_ES table.

The semantics of a one to one relationship are very similar to a secondary table so most of your application logic should work. Just check the reference for null (don't assume that the other side exists). If you query the CATEGORY_ES table you can go back to the CATEGORY table, but not necessarily the other way.

Craig

Craig L Russell
Architect, Sun Java Enterprise System http://db.apache.org/jdo
408 276-5638 mailto:[email protected]
P.S. A good JDO? O, Gasp!

Reply via email to