• Post Reply Bookmark Topic Watch Topic
  • New Topic

EntityBean wrong referece

 
Markus Skide
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi there,
i'm facing a strange problem.
i'm calling a entityBean from a jsp.
i can manipultate the entityBean. everything works fine.
but every once a while i get the wrong EJB reference back.
in my errLog File i can see that:
1) ejbFindByPrimary(pk) is OK
2) ejbActivate() is OK
3) ejbLoad() is OK
4) but now an ejbPassivate() from another EJB is called
5) henceforth every method called from the jsp is send to the EJB from the ejbPassivate() call
as i said before this happens every now and then.
i'm using jrun 3.0 sp2a / jdk 1.3 / linux 2.4
has anyone come accross this ?
mark

 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think we need some more information here.
What do you mean "an ejbPassivate() from the wrong EJB" is called? How can you tell? What are you using to determine that it's the "wrong" EJB? Is it the wrong data? Or are you somehow relying on the Object ID of the underlying bean implementation object?
Kyle
 
Markus Skide
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Kyle,
thanks for your response.
for debugging, every entity EJB callBack Method
starts with System.err.println(this.beanName+methodName+this.pk.id);
therefore i can see what going on.
the jsp code lookslike:
<%<br /> myModul = mHome.findByPrimaryKey(_id);<br /> <br /> defs = myModul.getModulDefs();<br /> ....<br /> out.println(defs.name);<br /> ...<br /> defs = null ;<br /> myModul = null;<br /> mHome = null ;<br /> %>

the debug info lookslike:
onSuccess:
ac_modulEJB ejbFindByPrimaryKey 1000000627
ac_modulEJB findBean: 1 1000000627
ac_modulEJB connect me is called ... source1
ac_modulEJB ...loadBean: found pk: 1000000627
ac_modulEJB ejbActivate() 1000000627
ac_modulEJB ejbLoad() 1000000627
ac_modulEJB ...loadQuery called
ac_modulEJB connect me is called ... source1
ac_modulEJB getModulDefs: 1000000627
------
onError it lookslike:
ac_modulEJB ejbFindByPrimaryKey 1000000627
ac_modulEJB findBean: 1 1000000627
ac_modulEJB connect me is called ... source1
ac_modulEJB ...loadBean: found pk: 1000000627
ac_modulEJB ejbPassivate(): 1000000671 <--- here we go
ac_modulEJB ejbPassivate(): 1000000671
ac_modulEJB ejbActivate() 1000000671
ac_modulEJB ejbLoad() 1000000671
ac_modulEJB ...loadQuery called
ac_modulEJB connect me is called ... source1
ac_modulEJB getModulDefs: 1000000671 <-- should be 1000000627

i don't know what's going on here.
any ideas ?
mark

 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this causing any problems with your application? I think this may just be a side-effect of the EJB container and should not be causing any problems.
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aha! I think I see your problem. The thing is that you CANNOT assume that the bean that executes ejbFindBy... in a BMP bean is the same bean to which ejbLoad() will be sent. That is pretty clear in the specification.
Think about it this way -- let's suppose you weren't wanting to do an ejbFindByPrimaryKey() -- instead suppose you wanted a finder method that returned a collection of primary keys -- then what role would the bean in which ejbFindByFoo() ran play? It can't be every bean in the collection, can it?
So, what you must do when programming BMP is to assume that ejbFindByPRimaryKey() and ejbLoad() will ALWAYS run in different beans. That's why (for instance) you have to use the primary key id in the Entity Context in ejbLoad() -- because this may be the first time that this bean has been invoked in this transaction. Your ejbFindByPrimaryKey() must be stateless -- it can't cache anything. Likewise, your ejbLoad() can't assume that anything is set in the bean before it runs.
Kyle
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.
[This message has been edited by Kyle Brown (edited December 03, 2001).]
[This message has been edited by Kyle Brown (edited December 03, 2001).]
 
Markus Skide
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi kyle,
thank you very much. now it works.
the mistake was, that in my ejbLoad() i used a global pk which was set in the findByPrimaryKey(). now i use context.getPrimaryKey() in ejbLoad(). should i use in all
bean methods that needs a pk the context.getPrimaryKey() ?

in this context i have another question.
how many ejbobjects ( beans ? ) were created in the container with the same pk ?
because if i call 10 times the same ejb, then stop the server, in my error.log, the container calls 10 times ejbPassivate() with the same pk. is this just one ejbobject whose ejbPassivate() is called 10 times, or were 10 ejbobject passivated ?
thanks in advance
mark
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!