Re: Teaching vertical inheritance to me ?
Re: Teaching vertical inheritance to me ?
- Subject: Re: Teaching vertical inheritance to me ?
- From: Chuck Hill <email@hidden>
- Date: Mon, 15 Nov 2004 12:00:21 -0800
I know you said it was your problem, but here are some ideas:
On Nov 15, 2004, at 2:39 AM, Wolfram Stebel wrote:
i have a complex application with a complex data modell.
I choose vertical inheritance for a classical businespartner<-->person
and
businespartner<-->mandant object structure (and more derived objects).
In my code i do the following:
CMandant newMandant = CMandant.newMandant ( ec );
CPerson newPerson = CPerson.newPersonForMandantAndPerson ( ec,
newMandant, null ); // relation to mandant and "self" is set!
where ec is the EOEditingContext, in which the Objects insert themself
after
creation.
Later on I do:
ec.saveChanges ();
PROBLEM 1:
- All initialization via " awakeFromInsertion" for the vertical derived
classes have to be handled in the derived class.
Not sure what you mean, but I suspect you are not calling
super.awakeFromInsertion() at the right time. As a rule, I make this
the first line in the awakeFromInsertion() of each subclass.
- When i have a "awakeFromInsertion" in the base class, the
construction
cycle fails.
That should not happen. What is the code in that method?
Probably because WO does "awakeFromInsertion" for "Mandant" and i call
"super" in there, which is "Businespartner", aaaannnndddd WO calls
"awakeFromInsertion" for the same "Businespartner" too.
You should never call any awakeFromInsertion other than
super.awakeFromInsertion.
QUESTION: Are all accessors of the base class unused? May i remove the
"member" carret in EOModeller?
No, they should get used.
PROBLEM 2:
- The above mentioned objects (2 businespartners and 1 person and 1
mandant)
are inserted into the database with the ec.saveChanges ().
- The reduced but still lengty sql trace shows 5 inserts where the last
fails:
A:
[2004-11-15 10:42:54 CET] <WorkerThread4> evaluateExpression:
<com.webobjects.jdbcadaptor.MySQLPlugIn$MySQLExpression: "INSERT INTO
MANDANT(MASCOT_PICT, ...., SHOP_MAP) VALUES (NULL, ....., NULL)"
withBindings: 1:0(test_duration), 2:1(pk_bupa), 3:1(fk_clubtype_key),
4:"gast"(mandant_alias), 5:2(allow_non_public), 6:1(fk_legalform_key),
7:2004-11-15 10:42:38(valid_since), 8:0(show_billing)>
B:
[2004-11-15 10:42:54 CET] <WorkerThread4> evaluateExpression:
<com.webobjects.jdbcadaptor.MySQLPlugIn$MySQLExpression: "INSERT INTO
BUSINESPARTNER(DIRECT_DEBIT, ....., NAMEADD_2) VALUES (?, ....., NULL)"
withBindings: 1:0(businespartner_direct_debit),
2:0(businespartner_type),
3:1(NeededByEOF0), 4:2004-11-15 10:42:38(businespartner_bupa_upd_date),
5:"Vereinsname"(businespartner_name), 6:1(businespartner_bupa_active),
7:2004-11-15 10:42:38(businespartner_bupa_create_date)>
C:
[2004-11-15 10:42:54 CET] <WorkerThread4> evaluateExpression:
<com.webobjects.jdbcadaptor.MySQLPlugIn$MySQLExpression: "INSERT INTO
PERSON(IS_USER, ....., LAST_LOGIN) VALUES (?, ....., ?)" withBindings:
1:0(is_user), 2:""(user_pw_answer), 3:2(pk_bupa), 4:0(children_count),
5:2004-11-15 10:42:42(date_from), 6:1(fk_personstatus_key), 7:"Someones
Name"(user_pw_question), 8:0(should_pick), 9:"gast"(user_pw),
10:2004-11-15
10:42:42(last_login)>
D:
[2004-11-15 10:42:54 CET] <WorkerThread4> evaluateExpression:
<com.webobjects.jdbcadaptor.MySQLPlugIn$MySQLExpression: "INSERT INTO
BUSINESPARTNER(DIRECT_DEBIT, ....., NAMEADD_2) VALUES (?, .......,
NULL)"
withBindings: 1:0(businespartner_direct_debit),
2:0(businespartner_type),
3:"Vorname"(businespartner_firstname), 4:2(NeededByEOF0),
5:"MitgliedsNummer"(businespartner_key_1), 6:2004-11-15
10:42:42(businespartner_bupa_upd_date), 7:"gast"(businespartner_name),
8:2(businespartner_bupa_active), 9:2004-11-15
10:42:42(businespartner_bupa_create_date)>
E:
[2004-11-15 10:42:54 CET] <WorkerThread4> evaluateExpression:
<com.webobjects.jdbcadaptor.MySQLPlugIn$MySQLExpression: "INSERT INTO
BUSINESPARTNER(NAMEADD_1, ......, PUBLISH_PRIV) VALUES (NULL, .......,
NULL)" withBindings: 1:1(pk_bupa)>
SQLException: SQLState(23000) vendor code(1062) msg: Duplicate key or
integrity constraint violation message from server: "Duplicate entry
'1' for
key 1"
The objects are connected via "pk_bupa". As you can see, Mandant has a
binding to it ("1") and Person too ("2"). In my understanding, the
first two
busonespartner should have a binding too, but they dont have.
Instead a third businespartner is inserted with an only binding for
pk_bupa
("1") followed by an error.
The 4 data sets have been written to the database with correct
pk_bupa's.
QUESTION: What the h... happens?
Is the binding "NeededByEOF0" the internaly used "pk_bupa"?
Why is there a third businespartner inserted (and probably a
fourth...)?
It sounds like you have used Owns Destination in the EOModel (this
makes EOF create the owned object immediately when awakeFromInsertion
is called) _and_ you are creating your own object for the destination.
This leaves two objects in the EC where you want only one. Either
choose Owns Destination and use the object that EOF creates, or uncheck
this and create your own.
Does anybody know a bit about this?
Do the two problems interfer, so that initialisation and persistence
influence each other?
Does the vertical inheritance technic work in real life?
Yes.
In short: is it my fault??? :-)
Yes. :-)
AND NOTE:
WebObjects can not handle attributes called "alias" (i dont know why i
used
this possibly reserved word :-) as a field name ), it will replace
bindings
not correctly.
Yes, reserved words make bad attribute names.
Chuck
--
Practical WebObjects - a book for intermediate WebObjects developers
who want to increase their overall knowledge of WebObjects, or those
who are trying to solve specific application development problems.
http://www.global-village.net/products/practical_webobjects
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden