• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Problem with Cache (filter/Hibernate)

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I don't know how the Hibernate Filter works and how does it maintain cache.
But i would like to maintain cache for my application.
In Hibernate when i am using two different application using same database.there when i insert some value in table using hibernate(here i think it maintains some internal cache.)Now when i enter 2nd value(its generating some internal id [reading from and/storing to cahe])
Now when in second application using hibernate again i try to insert some third value to same table i doesn't permit to insert this new value(As what we are thinking here internal hibernate cache is having some conflict with these two self generated ids.)

Can this kind of problem be resolved if i seriously want to use hiberate cache mechanism.

the other thing is that if i create my own cache mechanism (not by hiberanete) maintenane or say the speed will vary as every time updating
values will upload and next time will be able to read from cache.

For big application the time will increase.


Any suggestions.

Thanks.
 
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moved to the ORM foum where Hibernate is discussed.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hibernate has two caches. The "First Level Cache" is the Session cache and is implicit. Every object loaded into the same Session is in this cache. The "Second Level Cache" is a mechanism Hibernate provides to allow object to be loaded into another caching technology (such as JBoss Cache). You need to configure both the second level cache plus define in your mapping files which objects participate in this cache.


its generating some internal id


Hibernate, assuming your mapping files are correct, uses a records Primary Key to identify objects. It doesn't generate any other ID, internal or otherwise, to identify objects in the Session.


Now when in second application using hibernate again i try to insert some third value to same table i doesn't permit to insert this new value(As what we are thinking here internal hibernate cache is having some conflict with these two self generated ids.)


What is the Exception you see? When you say "self-generated" do you mean you are using the "assigned" primary key generation strategy and it is your own application that is providing the primary key value?


the other thing is that if i create my own cache mechanism (not by hiberanete) maintenane or say the speed will vary as every time updating
values will upload and next time will be able to read from cache.


Not sure I understand you here. Are you asking if using a cache will make the application run faster? If so, then the answer is usually yes, since you no longer have to go to the database for every object. However you increase the likelyhood of stale objects.
 
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hibernate knows two different types of cache:
1st level
2nd level

The first level cache has the same scope as the Session (hibernate Session, nothing to do with HTTP Session). There is nothing you can do to turn it off, it is there (well you can flush the session and evict entities from cache but usualy there is no need to do this)

The second level cache needs to be configured manually and unless you have configured your entities (in the mapping files or trough annotations) to be cacheable hibernate will not touch them.

What do you mean by error ? Can you show some exceptions ? Some code ?

Im just guessing and giving you some clues...(need more information from you)

Since hibernate uses the entity ID (the primary key) to lookup/store entities in the cache i doubt your problem has anything to do with 2nd level cache and since it is on different JVMs it is surely not the 1st level cache.

If you you have several applications working on the same DB, then you must use a ID generation mechanism which will create unique IDs, no matter what application calls it (e.g. Sequence, not "just counting up")

If you want to use a cache from different applications, then this cache must work in a cluster (e.g. jBoss tree cache). Otherwise the cache becomes "out of sync" and you read stale data from the cache.

And i would not suggest you create your own caching stuff... it's more complicated than you might think.


pascal
reply
    Bookmark Topic Watch Topic
  • New Topic