0

Here an example of my problem:

I have an entity called "Person" (Name: String. CityId: Integer) I have a relation between "Person" and "City", named "toCity". I use to add the "CityId" field in the ObjEntity definition (using the Cayenen Editor) because I need it for other purpose (I need to generate both the methods person.setCityId() and the person.setToCity())

But sometimes (not always) when I fetch a Person entity, I get a NULL value for the CityId field (even if is valued), while the relationship "toCity" is fetched correctly.

So:

person.getCityId() returns NULL while person.toCity().getCityId() is valued

Where I'm wrong ?

1 Answers1

0

I am always trying to avoid mapping FK columns as object properties, so it is hard for me to tell why it is not working (generally Cayenne makes no guarantees that such "redundant" mapping will work). However here is a workaround that will allow you to unmap that property without losing functionality:

class Person extends _Person {
   public int getCityId() {
      return getCity() != null ? Cayenne.intPkForObject(getCity()) : -1;
   }
}
andrus_a
  • 2,528
  • 1
  • 16
  • 10