Fabricio,
On Wednesday, July 23, 2003, at 10:40 AM, Fabricio Voznika wrote:
> Hi,
>
> I've gotta a question. I'm just starting with Cayenne, so it could
> all be non sense :-)
> Let's suppose I have a hollow object x. When I call x.getName(),
> this call will end up in the CayenneDataObject.readProperty(String)
> method bellow:
>
> CayenneDataObject:
> protected Object readProperty(String propName) {
> try {
> if (persistenceState == PersistenceState.HOLLOW) {
> dataContext.refetchObject(objectId);
> }
> } catch (Exception ex) {
> logObj.info("Error refetching object, making transient.",
> ex);
> setPersistenceState(PersistenceState.TRANSIENT);
> }
>
> return readPropertyDirectly(propName);
> }
>
> The check for hollow is made and then refetchObject(ObjectId) is
> called, which seems right. The problem is that refetchObject returns a
> new DataObject and nothing is done to the current object, so
> readProperty will always return null for a hollow object. Did I miss
> anything?
In this case "refetchObject" is used for its side effect, rather than
its return value. Since DataContext will make sure that no duplicate
objects are created for the same ObjectId, this object is simply
repopulated with the values from the database. No new object is created.
> I found this trying to figure out what would happen if I set a
> property in a hollow object and then read a property. Will the
> property I set be overridden? Oh, I'm using Cayenne 1.0rc1.
Hmm... I am looking at the code now, and you may have just found a
bug.... setXYZ must check for HOLLOW state as well, and do a refetch.
I'll investigate this some more.
Andrus
This archive was generated by hypermail 2.0.0 : Wed Jul 23 2003 - 10:47:08 EDT