Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiple Entity callback methods in entity hierarchy

 
srikanth pragada
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Anton Golovin
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Tomaszz Lewandowski
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Am I wrong?
 
srikanth pragada
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

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
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
     
    Christophe Verré
    Sheriff
    Posts: 14691
    16
    Eclipse IDE Ubuntu VI Editor
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    It's puzzling me, so I tried with Hibernate instead of Toplink. Guess what :

  • Overriding postLoad : "Earth loaded" is printed. Works as expected.
  • Renaming Earth#postLoad to Earth#postLoading (thus not overriding) : "Planet loaded", "Earth loaded" is printed. Works as expected


  • It looks like a Toplink bug.
     
    Anton Golovin
    Ranch Hand
    Posts: 476
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    All this means is that the developer teams took different meanings to the word override in the spec.
     
    Christophe Verré
    Sheriff
    Posts: 14691
    16
    Eclipse IDE Ubuntu VI Editor
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 476
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Rancher
    Posts: 42968
    73
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    David O'Meara
    Rancher
    Posts: 13459
    Android Eclipse IDE Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Are you aware that we have a wiki where all members are able to submit their own information?

    We already have a huge number of categories, you may want to look at the SCJP FAQ as an example of the resources already available.

    [Dave - removed some duplicate information]
    [ November 07, 2008: Message edited by: David O'Meara ]
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic