You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by vkulichenko <va...@gmail.com> on 2017/07/06 23:00:26 UTC

Re: Cache refresh because of hibernate versioning mechanism.

Hi Czeslaw,

Please properly subscribe to the mailing list so that the community can
receive email notifications for your messages. To subscribe, send empty
email to user-subscribe@ignite.apache.org and follow simple instructions in
the reply.


cszczotka wrote
> I’m using cache with read-through/write-through configuration and with
> database persistent store handled by hibernate Dao –s. Hibernate Dao –s (
> it is legacy code) also handling versioning and optimistic locking. 
> So situation looks like when I put into cache some entity this entity is
> written to database with version 1 set by hibernate but in cache I have
> entity with version 0. Calling get method on cache doesn’t help because
> this entity is in cache and load method from persistance store is not
> called.
> Do you have good way how to force ignite to refresh cache from DB ? I see
> in ignite documentation that I can subscribe on event
> EventType.EVT_CACHE_OBJECT_PUT and programmatically call load method on
> cache. Do you see better way ?  

I think it's better to configure CacheInterceptor and implement reload logic
in onAfterPut method. However, this will be a performance overhead.

-Val



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Cache-refresh-because-of-hibernate-versioning-mechanism-tp14394p14435.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Cache refresh because of hibernate versioning mechanism.

Posted by vkulichenko <va...@gmail.com>.
One more point. You don't have to and should not pass IgniteCache as a
parameter. Instead, you can inject Ignite into transient field in the
CacheStore implementation and then use it to acquire cache:

@IgniteInstanceResource
private transient Ignite ignite;

-Val



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Cache-refresh-because-of-hibernate-versioning-mechanism-tp14394p15035.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Cache refresh because of hibernate versioning mechanism.

Posted by vkulichenko <va...@gmail.com>.
Czeslaw,

To achieve best performance you should do data remodeling, get rid of
collections, store different types of objects in different caches and
reference them using foreign keys.

L2 cache can also be an option, but performance wise it will be less
effective.

-Val



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Cache-refresh-because-of-hibernate-versioning-mechanism-tp14394p15972.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Cache refresh because of hibernate versioning mechanism.

Posted by cszczotka <cs...@interia.pl>.
Hi,
Thanks for your response.
Hibernate dao return object with new version. Version is used for optimistic
locking mechanism. So we have hibernate dao -s and hibernate data model (
*.hbm.xml files). We want to avoid  (if possible) completely rewrite this
code. Another issue will be in our data model where we have a lot of
hibernate entities with one-to-many relation represented by entities
collection ( not id –s collection).  Something similar like User and Posts
relation:
https://github.com/apache/ignite/blob/master/examples/src/main/java-lgpl/org/apache/ignite/examples/datagrid/hibernate/HibernateL2CacheExample.java

The question is also if we are trying to use apache ignite in correct way ?
Maybe only correct way is to use apache ignite as L2 cache  for hibernate
dao –s ? 
Regards,
Czeslaw
 



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Cache-refresh-because-of-hibernate-versioning-mechanism-tp14394p15827.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Cache refresh because of hibernate versioning mechanism.

Posted by vkulichenko <va...@gmail.com>.
Hi Czeslaw,

Does myEntity object that is returned from DAO have old or new version
value?

Generally, your approach can work, but this looks like a serious performance
overhead. Can you clarify, how exactly this versioning is used? Do you
actually need it after switching to Ignite?

-Val



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Cache-refresh-because-of-hibernate-versioning-mechanism-tp14394p15034.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Cache refresh because of hibernate versioning mechanism.

Posted by cszczotka <cs...@interia.pl>.
Hi,
I see such solution. Passing to the store reference to cache (loadCache
method has second parameter varargs so I can pass cache here) and in write
method call replace on cache:

public void write(Cache.Entry<? extends MyEntityId, ? extends MyEntity >
entry) throws CacheWriterException {        
MyEntity myEntity = hibernateDao.saveOrUpdate(entry.getValue());
               cache.loadAll(Sets.newHashSet(myEntity.getId()), true, null);
}
Regards,
Czeslaw



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Cache-refresh-because-of-hibernate-versioning-mechanism-tp14394p14722.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Cache refresh because of hibernate versioning mechanism.

Posted by cszczotka <cs...@interia.pl>.
Hi,
Refer to your advice about implementing CacheInterceptor and onAfterPut
method. It does not help me. It is the same issue - operating on entity copy
because:

in method onAfterPut(Cache.Entry<K, V> entry)  Cache.Entry implementation it
is CacheLazyEntry and if I call entry.getValue I will get entity copy so
setting version on entity copy does not propagated this change to cache.


My question is still open: how to integrate ignite database store handled by
hibernate dao -s with versioning mechanism ?




--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Cache-refresh-because-of-hibernate-versioning-mechanism-tp14394p14718.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.