-
1. Re: ejb caching not working -a bug??
adrian.brock Mar 31, 2003 11:23 PM (in response to malian)What do you mean by
"executes query on the database everyime I get an instance of an entity"
Any finder except "findByPrimaryKey"
must go to the database.
The cache is a map of primary keys
to entity bean instances.
Regards,
Adrian -
2. Re: ejb caching not working -a bug??
malian Apr 1, 2003 10:41 AM (in response to malian)Thanks for replying. I didn't know that it only caches lookups for primary keys. It's really useless because most the time, the queries are not findByPrimaryKeys. Caching would be more useful if it queried instances in the memory instead of the database by doing a findall first and caching those beans. Is this a common approach for all ejb containers or just jboss?
-
3. Re: ejb caching not working -a bug??
malian Apr 1, 2003 10:43 AM (in response to malian)Thanks for replying. I didn't know that it only caches lookups for primary keys. It's really useless because most the time, the queries are not findByPrimaryKeys. Caching would be more useful if it queried instances in the memory instead of the database by doing a findall first and caching those beans. Is this a common approach for all ejb containers or just jboss?
-
4. Re: ejb caching not working -a bug??
malian Apr 1, 2003 11:06 AM (in response to malian)Thanks for replying. I didn't know that it only caches lookups for primary keys. It's really useless because most the time, the queries are not findByPrimaryKeys. Caching would be more useful if it queried instances in the memory instead of the database by doing a findall first and caching those beans. Is this a common approach for all ejb containers or just jboss?
-
5. Re: ejb caching not working -a bug??
malian Apr 1, 2003 3:26 PM (in response to malian)Thanks for replying. I didn't know that it only caches lookups for primary keys. It's really useless because most the time, the queries are not findByPrimaryKeys. Caching would be more useful if it queried instances in the memory instead of the database by doing a findall first and caching those beans. Is this a common approach for all ejb containers or just jboss?
-
6. Re: ejb caching not working -a bug??
malian Apr 1, 2003 3:27 PM (in response to malian)Thanks for replying. I didn't know that it only caches lookups for primary keys. It's really useless because most the time, the queries are not findByPrimaryKeys. Caching would be more useful if it queried instances in the memory instead of the database by doing a findall first and caching those beans. Is this a common approach for all ejb containers or just jboss?
-
7. Re: ejb caching not working -a bug??
malian Apr 1, 2003 3:31 PM (in response to malian)Thanks for replying. I didn't know that it only caches lookups for primary keys. It's really useless because most the time, the queries are not findByPrimaryKeys. Caching would be more useful if it queried instances in the memory instead of the database by doing a findall first and caching those beans. Is this a common approach for all ejb containers or just jboss?
-
8. Re: ejb caching not working -a bug??
adrian.brock Apr 1, 2003 8:51 PM (in response to malian)Hehe, got stung by the horrible jive cache
where the posts don't appear :-)
By default. the findByXXXX only retrieves the
primary keys. If the keys are already in cache
there is no extra database work.
I think there are plans in jboss4 to introduce
a more complicated cache/persistence engine.
This should be able to work out if a
query can be satisfied from cache.
In general this is a difficult problem.
e.g. an "order by" with some entities in cache
how do you know you have them all?
You'd end up building an in memory database
with the extra complication that some parts
aren't in memory (they're in the datastore).
If you are interested the findBy is implemented
by the CMPPersistenceManager and the
cache mostly by AbstractInstanceCache.
I guess a simple implementation would be to have
secondary indexes and a totally preloaded
cache.
You can setup hsqldb to be an in memory db,
but it has no transaction isolation and no
support for XA.
Regards,
Adrian -
9. Re: ejb caching not working -a bug??
malian Apr 2, 2003 4:15 PM (in response to malian)Yes, I couldn't see my posts, and so I thought they weren't posted, that's why there are so many of the same messages... hahaha. Well, this time I hope it works the first time, but thanks for getting back with me. I would certainly like to preload some of my beans totally in cache. Could you be more specific about how I can do that? Those beans that I want to cache are very stable, they don't change often, and they do use orderby clause. You said that:"By default. the findByXXXX only retrieves the primary keys. If the keys are already in cache there is no extra database work." Does this mean that jboss looks in the cache first, then database? In my tests, every findby went to the database, even if I had ran the query right after another. Also, it would be great if you could explain in more detail how I can do what you said here: "I guess a simple implementation would be to have secondary indexes and a totally preloaded
cache."
Thank you very much!
Malia -
10. Re: ejb caching not working -a bug??
adrian.brock Apr 2, 2003 5:40 PM (in response to malian)A simple way to load everything into cache
is to write an MBean that in its start() method
does findAll() an then access something in
each bean such as getID. Specify "onFind"
as the loading strategy will probably speed
this up.
findByPrimaryKey is served from cache,
every other finder goes to the db.
The thing I was talking about isn't implemented
in jboss. e.g.
findByName() has some index over the cache
by name.
Regards,
Adrian