This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Java Reflection Issue resulting in Read Only Transaction Error  RSS feed

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two data sources (persistent contexts) one is Read Only, and one is for Read-Write, everyone pointing to a different database.

Read-Only is configured to be outside of JTA, as I going to only read from it.

So in this way, we're migrating all related to reads/fetch/gets from database to retrieve data from the read only DB.

Take a look at this code:



pEm is the entity manager, as you know the find searches for the ActionItem, then it updates with the LocalDateTime, then it use the 'merge' function...

Problem is, in pEm.find inside of the function (that i've overrided) i use the read only entity manager, so it fetch from the read DB, problem is with the merge, because it's giving me an ERROR saying:

Caused by: org.postgresql.util.PSQLException: ERROR: cannot execute UPDATE in a read-only transaction



And it's because inside of the merge, i use reflection to get the same object from the read-write entity manager, to enabled transaction to commit in the read-write, but for some reason it's not working, this is the merge function:


Thing is, if i perform the get reference outside the merge, it works, like this...



Any idea would be appreciated... (help help help)
 
author & internet detective
Sheriff
Posts: 38564
654
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not add a pm.findForUpdate() method? Then you can find using the read/write entity manager.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!