I am trying to use 2nd level caching for Hibernate with EHCache. I have some entities configured in the application that I have tagged with @Cache and I see that they are used by EHCache correctly.
However what I have observed is that when I save/update any other entity that is not supposed to be cached; I see that it gets added to the cache by the put() method. The retrieval of the data puts the non-cached object into the cache but not the insert operation.
This behaviour doesn't seem right to me as we should only add the cached objects to the cache and not any object on the save/update operation.
Am I missing something here?
I see the entities being added in the logs when I do any save/update operation. The entities are not added to the cache as part of the save (the log statement is after the save operation); but when I retrieve the object back as part of the session cache it gets added to the 2nd level cache.
2011-07-18 11:33:21 INFO [org.springframework.jms.listener.DefaultMessageListenerContainer#0-1] AbstractHibernateDAO.save(83) | Saved entity with class: Inventory
2011-07-18 11:33:22 DEBUG [org.springframework.jms.listener.DefaultMessageListenerContainer#0-1] EhcacheGeneralDataRegion.put(83) | key: FQNG_INVENTORY value: 5369729281208320
2011-07-18 11:33:23 DEBUG [org.springframework.jms.listener.DefaultMessageListenerContainer#0-1] EhcacheGeneralDataRegion.put(83) | key: FQNG_INVENTORY value: 5369729038065664None of these objects have the @Cache annotatation.
Code:
@Entity
@org.hibernate.annotations.Entity(dynamicUpdate = true)
@Table(name = "FQNG_INVENTORY")
@SuppressWarnings("serial")
public class Inventory implements Serializable {