Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7158819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:07:46+00:00 2026-05-28T13:07:46+00:00

Hibernate complains, Caused by: java.lang.UnsupportedOperationException: Can’t write to a readonly object at org.hibernate.cache.ReadOnlyCache.lock(ReadOnlyCache.java:68) for

  • 0

Hibernate complains,
Caused by:

java.lang.UnsupportedOperationException: Can’t write to a readonly
object at
org.hibernate.cache.ReadOnlyCache.lock(ReadOnlyCache.java:68)

for class which has @Cache(usage = CacheConcurrencyStrategy.READ_ONLY) but which is not modified. Class A has a many-to-many relationship with Class B defined via annotation,

    @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @MapKey(name = "abbreviation")
    private Map<String, B> allBs;

I am creating a new object of Class A and associating it with an existing object of Class B but for some unknown reason Hibernate tries to modify the version and the lastmodified time of Class B.

If I remove the read_only annotation it works fine and for no reason the version and last modified date of B gets updated apart from an entry in the joining table a_b;

Is this something that Hibernate does – Write B even if only a new association is added and the object itself is not changed?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T13:07:46+00:00Added an answer on May 28, 2026 at 1:07 pm

    It appears that Hibernate tries to lock objects during certain operations which are permitted even for read-only-cacheable entities. I ran across this whilst trying to delete one (with the Infinispan cache). However, a lower-level part of hibernate for dealing with read-only caches throws an exception whenever any locking is attempted because (I presume) it considers that to signify an intention to modify the entity.

    This appears to me to be incorrect behaviour on the part of Hibernate. Try commenting out the throwing of the exception in ReadOnlyCache (and in org.hibernate.cache.infinispan.entity.ReadOnlyCache.java, too), and returning null where necessary. Then recompile hibernate/replace those .class files in the jar. I can’t promise this won’t introduce a bug relating to concurrent cache access, although it does appear to work for me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hibernate has a handful of methods that, one way or another, takes your object
With Hibernate, can you create a composite ID where one of the columns you
Does hibernate provide a method that returns an object's state (transient, persistent, detached)?
Using hibernate, how can I persist a class with a List<String> field? Consider the
Can Hibernate 3.5.x be used as the JPA provider instead of the default provider
I am using Hibernate in a Java application to access my Database and it
We're running a java/hibernate app going against ORACLE 10g in TESTING. Once in a
Am I correct in saying Hibernate 3.6.5 does not support write-behind caching (implemented by
I am working on a webapplication where we are using Hibernate for persisting object
Hibernate allows adding indexes on @ManyToOne mappings by the use of @org.hibernate.annotations.Index . Is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.