aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes DB updated on quering the Entity getMethod? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "DB updated on quering the Entity getMethod?" Watch "DB updated on quering the Entity getMethod?" New topic
Author

DB updated on quering the Entity getMethod?

Nilesh Nadiyana
Greenhorn

Joined: Dec 24, 2002
Posts: 21
Hi!
a trivial question:
Does accessing a quering method say myentity.getStatus() would cause the DB trigger(insert/update) to be fired?
<snip>
myentity = myentityhome.findby(id);
myentity.getStatus();
<snip>
Regards,
Nilesh.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Can't say, really. It depends on whether the result is returned from a cache.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Nilesh Nadiyana
Greenhorn

Joined: Dec 24, 2002
Posts: 21
Thanks for response. However, How do I know whether the cache is enabled or it is coming from cache?
I am using weblogic 4.5.1.
The problem is :
we have a servlet.
From the servlet, It finds an entity bean based on id. (somehow session has it).
checks whether the status of the found bean (record) is "cancel" and throws an "application exception" (kind of validation).
However, At the end of this operation, the lastediteddate of the table gets updated to system date. This is due to execution of a trigger which says:
on insert/update of table, update last edited date to sysdate.
This means, the trigger gets fired. But the code does not do any update ("Set" methods).
Thanks in advance for clarifying my doubt.
Regards,
Nilesh.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Sorry, I didn't get (pun intended ) that you were talking about only a get method... I don't know why WebLogic 4.5.1 makes an UPDATE even though you're only querying the entity. You probably have double-checked that the trigger is not executed on SELECTs as well, right?
I'd suggest turning to BEA forums/support.
[ December 15, 2003: Message edited by: Lasse Koskela ]
JeanLouis Marechaux
Ranch Hand

Joined: Nov 12, 2001
Posts: 906
Originally posted by Lasse Koskela:
I'd suggest turning to BEA forums/support.

If you can find someone with WebLogic 4.5.1 knowledge there !
It's quite an old version.
[ December 15, 2003: Message edited by: Jean-Louis Marechaux ]

/ JeanLouis<br /><i>"software development has been, is, and will remain fundamentally hard" (Grady Booch)</i><br /> <br />Take a look at <a href="http://www.epfwiki.net/wikis/openup/" target="_blank" rel="nofollow">Agile OpenUP</a> in the Eclipse community
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Originally posted by Nilesh Nadiyana:
Does accessing a quering method say myentity.getStatus() would cause the DB trigger(insert/update) to be fired?

Calling the getFoo() method should not cause an update to occur. However, I was seeing this behavior (WebLogic 7.0.1) and found that it was my misunderstanding. I put a call to setModifiedDate() in my base entity bean's ejbStore() method after reading WebLogic's documantation that says that ejbStore() is called if the bean has been modified.
That turns out not to be the case, though -- instead ejbStore() is called as a result of the bean being involved in a transaction, whether or not the bean was modified. WebLogic's generated ejbStore() method first calls super.ejbStore(), then it checks to see if the bean has been modified and saves it to the DB if so.
Moral: make sure your ejbStore() method doesn't modify the bean or the bean will *always* be modified whenever it is involved in a transaction.
 
Consider Paul's rocket mass heater.
 
subject: DB updated on quering the Entity getMethod?