• Post Reply Bookmark Topic Watch Topic
  • New Topic

why use ctx.getPrimaryKey() to remove entitybean  RSS feed

 
Prakash Dwivedi
Ranch Hand
Posts: 452
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Friends,
I was reading entity beans from ed roman, there it is mentioned that to find out which entity bean is to be removed(when ejbRemove() is invoked). we should take primary key from ctx.getPrimaryKey(). My problem is that each entity bean instance represents a single row in a table, so we can easily store primary key as an instance variable, and use that variable whenever required. why take trouble to call ctx.getPrimaryKey()?
plz clear my doubts
 
Simon Brown
sharp shooter, and author
Ranch Hand
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's probably to be on the safe side, to ensure that the correct bean is removed. As bean instances are pooled by the container, it is possible that an instance variable representing the PK field might not get set correctly when the bean instance is bought into an active state with identity.
Anybody else have any thoughts about this?
Simon
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!