This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Data updated through stored proc is not retrieved by subsequent em.find() calls  RSS feed

 
Pushker Chaubey
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi experts,

I am facing a very interesting problem. After updating an entity through EntityManager API, I update the data through a stored proc via a jdbc connection object. both the updates - done by em and stored proc are reflected in database. Then in another call to em.find() is made but that does not reflect the changes done by stored proc.

the code flow looks like the following...

..
..//do some changes in entity
..
em.flush();

callToStoredProc(); // this method invokes stored proc via connection object obtained from datasource and does updates

em.clear();
..


And then from within another session bean I call em.find() which does gives me back the data updated through stored proc.

Please provide solutions to my problem.

Thanks in advance!

regards,
Pushker Chaubey
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the connection isolation level on the datasource?
 
Pushker Chaubey
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for showing interest in this problem. I am not sure about isolation level and code is not available right now, so can't look into.
Please let me know in this situation what should be the isolation level set to for data-source connections and for Entitymanager settings? your inputs please...

Also, please note that we are using container managed transaction here and we have NOT declared any transaction attribute on the method callToStoredProc(). I believe though the method callToStoredProc() executes in the propagated transaction, the updates done using connection object are NOT going to be in the same transaction. Please correct me if I am wrong.

We are using Hibernate's JPA provider. Though we were able to get around the problem by getting access to hibernate session factory and then evicting the entity. But here the use of Hibernate's proprietary API is not being accepted and they want me to use only standard JPA APIs to fix it (In order to have no dependency on underlying JPA provider).

Your input are welcome.

Regards,
Pushker Chaubey
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!