-->
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.  [ 9 posts ] 
Author Message
 Post subject: Entity cache not being found by Hibernate??
PostPosted: Mon Mar 15, 2004 2:58 pm 
Beginner
Beginner

Joined: Thu Aug 28, 2003 3:09 pm
Posts: 39
Location: Brazil
Hi all,

I'm testing cache with hibernate, but from hibernate logging, I think it is not finding the entities in ehcache:

2004-03-15 15:48:20,430 DEBUG [net.sf.hibernate.impl.SessionImpl] loading [Processo#277]
2004-03-15 15:48:20,430 DEBUG [net.sf.hibernate.impl.SessionImpl] attempting to resolve [Processo#277]
2004-03-15 15:48:20,430 DEBUG [net.sf.hibernate.cache.ReadWriteCache] Cache lookup: 277
2004-03-15 15:48:20,430 DEBUG [net.sf.ehcache.hibernate.Plugin] key: 277
2004-03-15 15:48:20,430 DEBUG [net.sf.ehcache.store.MemoryStore] ProcessoCache: MemoryStore hit for 277
2004-03-15 15:48:20,430 DEBUG [net.sf.ehcache.store.MemoryStore] ProcessoCache: MemoryStore hit for 277
2004-03-15 15:48:20,431 DEBUG [net.sf.hibernate.cache.ReadWriteCache] Cached item was locked: 277
2004-03-15 15:48:20,431 DEBUG [net.sf.hibernate.impl.SessionImpl] object not resolved in any cache [Processo#277]
2004-03-15 15:48:20,431 DEBUG [net.sf.hibernate.persister.EntityPersister] Materializing entity: [Processo#277]

Am I missing something??

I'm using hibernate 2.1.2, ehcache 0.7 and jboss 3.2.3

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 17, 2004 9:56 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You should be more specific

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 18, 2004 5:28 pm 
Beginner
Beginner

Joined: Thu Aug 28, 2003 3:09 pm
Posts: 39
Location: Brazil
Hi Emmanuel.

Well, from this log, I'm seeing that hibernate is querying ehcache for an entity and ehcache seems to find it as it says:

ProcessoCache: MemoryStore hit for 277

But Hibernate seems to be not finding it as Hibernate says:

object not resolved in any cache [Processo#277]

Is this the expected message output?


I got this log when trying to reload an object twice with Session.load. Later I tried with session.find.

Is there any test I can do which can show me if my entities are being cached correctly by ehcache and being used by hibernate?

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 18, 2004 7:07 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Hibernate enforces certain txn isolation semantics when reading from the cache. Looks like this (correct behavior) is the cause.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 20, 2004 2:31 pm 
Beginner
Beginner

Joined: Thu Aug 28, 2003 3:09 pm
Posts: 39
Location: Brazil
Hi Gavin.

Thanks. Is there anything I can do to make Hibernate to use ehcache instead?

I'm using DTO's to keep track of changes done in presentation. I later use my assembler to change back this DTO to an entity. To avoid me to track every change done in DTO and copy it back to entity, I'm using saveOrUpdateCopy to do that for me :) With this, Hibernate also can handle updates in collections and do the cascade-delete-orphan correctly to me.

The issue is to do that, Hibernate has to load the entity again, but as I already loaded it in a previous session I'd like hibernate get this entity loaded previously instead of hit the database again.


Is this possible?

Is there some way I can accomplish that?

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 20, 2004 2:38 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Handle your txns correctly and it will Just Work.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 20, 2004 3:23 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
post code sample, copyproperties, transaction, opening session, commiting.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 23, 2004 5:01 pm 
Beginner
Beginner

Joined: Thu Aug 28, 2003 3:09 pm
Posts: 39
Location: Brazil
Here is what I'm trying to do:

I have the folowing: Entities translated to DTO and sent to presentation layer. In presentation, there may be modifications in collections in parent child relationships.

These DTO modifieds are sent back and processed. We have collections with cascade=all-delete-orphan.

Problem: If some child is removed, hibernate will not handle it as it won't know a child has been deleted. (with saveOrUpdate()). This is caused by the fact that the original hibernate collection has been lost in the entity <-> dto conversion.


In order I don't have to manually check for every collection modified in the parent child, I looked for an hibernate method which could do that for me. At least it seems that saveOrUpdateCopy() helped me with that. It could handle what has been changed even in the parent child collections! :) But obviously this didn't came for free... Hibernate has to load the entity again so it can do its magic :)

Here is where I came to the idea of using ehcache. This way, I could use the entity cache when hiberante loaded the entity the first time, which would avoid a database query when calling saveOrUpdateCopy() as the entity would be loaded from cache.

But entity still was being loaded from database :( And so I watched the logs and got that.

My transactions are being handled by jboss, I'm not using transaction API. I'm closing my sessions in finally blocks.

Am I missing something? Is what I'm trying to do possible or is it absurd?

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 23, 2004 5:03 pm 
Beginner
Beginner

Joined: Thu Aug 28, 2003 3:09 pm
Posts: 39
Location: Brazil
delpouve wrote:
post code sample, copyproperties, transaction, opening session, commiting.


delpouve, my code is a simple hibernate usage with ehcache. But I will post the code here. I'm not in my devel box right now.

Regards,


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

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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.