2016-08-04 2 views
4

私はspring3.xからspring4.3.xに移行しています。私は春-4.3.0.RELEASEを使用していますspring4.3.xで 'entityCacheStrategies'を設定する方法

Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'entityCacheStrategies' of bean class [org.springframework.orm.hibernate5.LocalSessionFactoryBean]: Bean property 'entityCacheStrategies' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter? 
at org.springframework.beans.BeanWrapperImpl.createNotWritablePropertyException(BeanWrapperImpl.java:242) 
at org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:423) 
at org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:280) 
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:95) 
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:75) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1514) 
... 66 more 

私は、次のエラーを取得しています

<bean id="sessionFactory" 
     class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"> 
    <property name="annotatedClasses"> 
     <list> 
      <value>com.example.person.domain.Person</value> 
     </list> 
    </property> 

    <property name="mappingLocations"> 
     <list> 
      <value>classpath*:com/example/person/domain/Person.hbm.xml</value> 
     </list> 
    </property> 

    <property name="hibernateProperties"> 
     <props> 
      <prop key="hibernate.dialect">${hibernate.dialect}</prop> 
      <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop> 
      <prop key="hibernate.cache.use_query_cache">true</prop> 
      <prop key="hibernate.cache.provider_class">${cache.providerClass}</prop> 
      <prop key="hibernate.generate_statistics">true</prop> 
      <prop key="hibernate.memcached.dogpilePrevention">true</prop> 
      <prop key="hibernate.memcached.servers">${cache.memcached.servers}</prop> 
      <prop key="hibernate.memcached.keyStrategy">com.example.memcached.ExampleCacheStringKeyStrategy</prop> 
      <prop key="hibernate.memcached.deviceAttributeDao.keyStrategy">com.googlecode.hibernate.memcached.HashCodeKeyStrategy</prop> 
      <prop key="hibernate.memcached.EncodingDao.keyStrategy">com.googlecode.hibernate.memcached.HashCodeKeyStrategy</prop> 
     </props> 
    </property> 

    <property name="entityCacheStrategies"> 
     <props> 
      <prop key="com.example.person.domain.TestAttribute">read-write,_domain</prop> 
     </props> 
    </property> 

    <property name="dataSource" ref="dataSource"/> 
</bean> 

を次のように私は、Beanの作成にorg.springframework.orm.hibernate5.LocalSessionFactoryBean使用しています。 LocalSessionFactoryBeanには、entityCacheStrategiesの設定がありません。これをspring4.3.xでどのようにサポートするか考えていますか?

答えて

1

entityCacheStrategies/setEntityCacheStrategies()の使用は、休止状態5では廃止されました。org.hibernate.cfg.Configuration : setCacheConcurrencyStrategy(String clazz, String concurrencyStrategy)からの代替方法も使用されなくなりました。

しかし、hibernateアノテーションライブラリを使用してキャッシュを設定することができる場合は、CacheConcurrencyStrategy列挙子を使用するthis approachを試してください。 適切なConcurrency戦略をEntityレベルに適用することができます。

@Entity 
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY) 
public class Clazz{..} 

dev guideCacheConcurrencyStrategyのより多くの用途を見つけてください。

関連する問題