2 Replies Latest reply on Mar 20, 2013 6:46 AM by h3m3r

    Infinispan as Hibernate SLC: java.lang.UnsupportedOperationException: Illegal attempt to edit read only item

    h3m3r

      Hello,

       

      I am trying to use Infinispan as Hibernate SLC instead of EHCache.

       

      I have a lot of READ_ONLY entities (only for inserting) so I annotated entitities with:

       

      @Cache(usage = CacheConcurrencyStrategy.READ_ONLY).
      @Immutable
      @Entity
      public class Message implements java.io.Serializable {}
      

       

       

      And when some entity has immutable collention, I annotated getter with:

       

      @Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
      @Immutable
      public Set<Tag> getTags() {}
      

       

       

      This works perfectly with EHCache, but when I try to insert (em.persist) with Infinispan as SLC, I get:

       

      java.lang.UnsupportedOperationException: Illegal attempt to edit read only item

                at org.hibernate.cache.infinispan.collection.ReadOnlyAccess.lockItem(ReadOnlyAccess.java:25) [hibernate-infinispan-4.0.1.Final.jar:4.0.1.Final]

                at org.hibernate.action.internal.CollectionAction.beforeExecutions(CollectionAction.java:101) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]

       

       

      My persistence.xml:

       

      <?xml version="1.0" encoding="UTF-8" standalone="no"?>
      <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
        <persistence-unit name="fis-messaging" transaction-type="JTA">
        <description>FIS Messaging Persistence Unit</description>
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>java:jboss/datasources/FISMessagingDatasource</jta-data-source>
        <exclude-unlisted-classes>false</exclude-unlisted-classes>
        <properties>
        <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
        <property name="hibernate.hbm2ddl.auto" value="${hibernate.hbm2ddl.auto}"/>
        <property name="hibernate.show_sql" value="${hibernate.show_sql}"/>
        <property name="hibernate.format_sql" value="${hibernate.format_sql}"/>
        <property name="hibernate.transaction.flush_before_completion" value="true"/>
        <property name="hibernate.transaction.auto_close_session" value="true"/>
      
        <property name="hibernate.cache.use_second_level_cache" value="true" />
        
        </properties>
        </persistence-unit>
      </persistence>
      

       

       

      When I use CacheConcurrencyStrategy.TRANSACTIONAL it works wine. Am I doing something wrong or this is a bug?

       

      Thanks for advice,

       

      Vaclav Chalupa.