Multiple Entity callback methods in entity hierarchy
srikanth pragada
Greenhorn
Joined: Nov 08, 2006
Posts: 7
posted
0
Hi Everyone,
I have created the following code.
The application is deployed successfully. I am using Glassfish and TopLink. But when an Employee entity is loaded using find() method, it is causing error which says that multiple methods are present for the same event.
But SPECS say the following in Section 3.5.4.
If a lifecycle callback method for the same lifecycle event is also specified on the entity class and/or one or more of its entity or mapped superclasses, the callback methods on the entity class and/or superclasses are invoked after the other lifecycle callback methods, most general superclass first. A class is permitted to override an inherited callback method of the same callback type, and in this case, the overridden method is not invoked.
I have tried to override the same method. It is calling the method in subclass ( correctly).
Can anyone explain what's wrong with the above code.
Srikanth.
SCJP 5.0 (97%), SCWCD 1.4 (92%), SCBCD 5.0 (96%)
Anton Golovin
Ranch Hand
Joined: Jul 02, 2004
Posts: 473
posted
0
If a lifecycle callback method for the same lifecycle event is also specified on the entity class and/or one or more of its entity or mapped superclasses, the callback methods on the entity class and/or superclasses are invoked after the other lifecycle callback methods, most general superclass first. A class is permitted to override an inherited callback method of the same callback type, and in this case, the overridden method is not invoked.
This is a tricky wording: nowhere does it say the same lifecycle event could be specified several times in a hierarchy. You could, however, override an inherited callback method, but i think overriding in this case literally means the same method name. [ November 04, 2008: Message edited by: Anton Golovin ]
Anton Golovin<br /><i>anton.golovin@gmail.com</i><br />SCJP, SCJD, SCBCD, SCWCD
Tomaszz Lewandowski
Ranch Hand
Joined: Sep 07, 2007
Posts: 30
posted
0
Hello,
I don't agree with this, because of the sentence:
"If a lifecycle callback method for the same lifecycle event is also specified on the entity class and/or one or more of its entity or mapped superclasses, the callback methods on the entity class and/or superclasses are invoked after the other lifecycle callback methods, most general superclass first."
I think that this sentence describes exactly above situation and it assumes that the same lifecycle event could be specified several times in a hierarchy.
Yes. What I Understand from the SPECS is that we can have a method in superclass as well as subclass for the same event. But that is NOT the case with TopLink.
Who is wrong? SEPCS cannot be wrong. Is TOPLINK not doing what it should?
I am preparing for SCBCD 5.0. These inconsistensies could come in my way and take a question or two from me in the exam. I am worried about that.
Can idea about what stand should we take?
Thanks, Srikanth.
Anton Golovin
Ranch Hand
Joined: Jul 02, 2004
Posts: 473
posted
0
Then for portability reasons, you might want to simplify your callbacks. Generally speaking, the amount of bugs in persistence providers is terrible. They should make a qualitative assessment of the persistence providers the first question on that exam.
Did you manage to rename your method and see what TopLink thought about it? [ November 05, 2008: Message edited by: Anton Golovin ]
Satya Maheshwari
Ranch Hand
Joined: Jan 01, 2007
Posts: 368
posted
0
Did you manage to rename your method and see what TopLink thought about it?
In toplink, if I have the same named postload callback in the entity and its mapped superclass, the callback in made twice to the postlaod callback method of the entity. On the other hand, as already stated, for different named callback methods, an exception is throw saying that there cannot be multiple call back methods for the same event. Is this a bg with toplink?
This is what I have with Oracle TopLink Essentials 2.0.1 :
Overriding postLoad : "Earth loaded" is printed. Works as excected.
Renaming Earth#postLoad to Earth#postLoading (thus not overriding) : deployment fails : The listener class [class com.webage.ejbs.mappedsuperclass.Earth] has multiple lifecycle callback methods for the same lifecycle event ([public void com.webage.ejbs.mappedsuperclass.Planet.postLoad()] and [public void com.webage.ejbs.mappedsuperclass.Earth.postLoading()]).
Mmmh, as Srikanth Praga says, that's not what I would expect.
The closest I've found is this bug, but it is still a bit different from what we have here.
No, the problem here is not about the overriding part, as it's working fine. The problem is in the first part: If a lifecycle callback method for the same lifecycle event is also specified on the entity class and/or one or more of its entity or mapped superclasses, the callback methods on the entity class and/or superclasses are invoked after the other lifecycle callback methods, most general superclass first.
Anton Golovin
Ranch Hand
Joined: Jul 02, 2004
Posts: 473
posted
0
Why don't the bartenders post a set of links to free online resources?
[ November 07, 2008: Message edited by: Anton Golovin ] [ November 07, 2008: Message edited by: Ulf Dittmer ]
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35258
7
posted
0
Why don't the bartenders post a set of links to free online resources?
I'm assuming you're asking about the SCBCD, since that's what this forum is about. Such a page exists already: http://faq.javaranch.com/java/ScbcdLinks Being a wiki page, everyone can contribute to it.