• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Reflection Issue resulting in Read Only Transaction Error  RSS feed

 
Ricardo Coto
Ranch Hand
Posts: 30
  • 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)
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37384
531
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!