-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: persistence.xml classcache read-only useless?
PostPosted: Thu Sep 30, 2010 6:13 am 
Newbie

Joined: Thu Sep 30, 2010 5:53 am
Posts: 1
Hello

I have a jar with some EJB 3.0 beans (no hibernate specific annotation) wich are used by serveral projects.
I want to use them now with Hibernate and EHCache inside an Appserver, without a large configuration overhead.
So I choose to use only the persistence.xml and ehcache.xml.
It is possible to use the property hibernate.ejb.classcache... to enable read-only cache, as I dont want to write to these beans.
However, Hibernate still want to write to these objects, and I get the exception:
Code:
java.lang.UnsupportedOperationException: Can't write to a readonly object
    at net.sf.ehcache.hibernate.strategy.ReadOnlyEhcacheCollectionRegionAccessStrategy.lockItem(ReadOnlyEhcacheCollectionRegionAccessStrategy.java:74)
    at org.hibernate.action.CollectionAction.beforeExecutions(CollectionAction.java:88)
    at org.hibernate.engine.ActionQueue.prepareActions(ActionQueue.java:285)
    at org.hibernate.engine.ActionQueue.prepareActions(ActionQueue.java:194)
    at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:320)
    at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
    at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1206)
    at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:375)
    at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:1001


1)How can this problem be resolved?

2)I have seen that the properties mutable="false", or flushmode="MANUAL" could help. However, It is not possible to define these in the persistence.xml. I would have to create a hbm.xml file, but then I could also write the read-only cache setting in there. Which means that the possibility to configure read-only inside persistence.xml is useless here.


My persistence.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
        xmlns="http://java.sun.com/xml/ns/persistence"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
    <persistence-unit name="myPU" transaction-type="JTA">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>jdbc/PostgresDS</jta-data-source>
        <jar-file>BEANS.jar</jar-file>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
            <property name="hibernate.cache.region.factory_class" value="net.sf.ehcache.hibernate.EhCacheRegionFactory" />
            <property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.EhCacheProvider" />
            <property name="net.sf.ehcache.configurationResourceName" value="META-INF/ehcache.xml" />
            <property name="hibernate.cache.use_second_level_cache" value="true" />
            <property name="hibernate.cache.use_query_cache" value="true" />
            <property name="hibernate.ejb.classcache.entityBeans.BEAN1" value="read-only"/>
            ...           
        </properties>
    </persistence-unit>
</persistence>


My ehcache.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
         updateCheck="true"
         monitoring="autodetect"
         dynamicConfig="true">

    <diskStore path="java.io.tmpdir"/>

    <defaultCache
      maxElementsInMemory="1000"
      maxElementsOnDisk="1"
      eternal="false"
      overflowToDisk="false"
      timeToIdleSeconds="60"
      timeToLiveSeconds="120"
      memoryStoreEvictionPolicy="LRU"/>

   <cache name="org.hibernate.cache.StandardQueryCache"
      maxElementsInMemory="10"
      eternal="false"
      timeToLiveSeconds="120"
      overflowToDisk="false"/>
      
   <cache name="org.hibernate.cache.UpdateTimestampsCache"
      maxElementsInMemory="5000"
      eternal="true"
      overflowToDisk="false"/>

</ehcache>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.