Re: Use of derived Attributes
Re: Use of derived Attributes
- Subject: Re: Use of derived Attributes
- From: Jonathan Rochkind <email@hidden>
- Date: Mon, 26 Apr 2004 11:20:59 -0500
You are more or less correct in your understanding of what's going
on. A derived attribute is based on SQL that is executed at time of
fetch. A newly created object was never fetched, so it doesn't have
a value here. There are a variety of ways we could later force the
object to be "refetched" (short of restarting the whole app!), but...
If it were me, I woudln't make this a derived attribute. I'd just
make it a _method_ in my code:
public String fullName() {
return lastName() + " " + firstName();
}
Now calling fullName() will always be based on the in-memory values
of lastname and firstname, we don't care if they've been saved to the
db yet or if they are pending changes, we don't care if they came
from a newly inserted object or were fetched.
I don't use D2W, so I'm not sure how you get your D2W pages to _use_
this method properly for display, as it is _not_ an attribute, it's
just a method on your object. But there must be some good way.
--Jonathan
At 4:21 PM +0100 4/25/04, Steve Sharman wrote:
Dear all,
I have an entity called (originally!) person, which has attributes
lastName and firstName in it. I also have a derived attribute called
fullName, which is defined in EOModeler as lastName+','+firstName,
external type varchar. I am using fullName in a number of list
pages in my D2W application.
In my simple D2W application, when a new person object is created
and a search then executed that will return results including the
newly created object, that new object appears as expected, but with
a blank fullName. If I shut the instance down and restart, and
re-execute the search, then the new object appears in the results
list, with the fullName presented as expected.
I think I understand what the problem is - presumably EOF is caching
the newly created object in memory on the server, and when it is
returned by the first search, fullName is blank because this would
normally be generated during the fetch from the database? Shutting
down WO obviously flushes the cache etc, and so when the object is
then fetched from the database, the derived attribute is generated
correctly....
So.... is my understanding of the situation about right - and
regardless, is there something that I can do to overcome the
situation? Can I not use derived attributes in D2W applications, or
is there some way of forcing new objects to be refetched from the
database before being used (this feels like it is going against EOF
in some way....).
I'm using WO 5.2.3 on Panther 10.3.3, Java 1.4.2, database is Sybase.
Many thanks for any suggestions and help,
-- Steve
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.