Results 1 to 3 of 3

Thread: Hibernate cache ?

  1. #1
    Join Date
    Aug 2005
    Posts
    14

    Default Hibernate cache ?

    hi

    I have a couple of "data dictionaries" tables in my database, that i'm sure won't change in a whole deploy-time, so obviously i want them cached by hibernate. Each access to those tables whether it's by "getHibernateTemplate().find..." or loadAll() or simply as a property (FK) of other object, or whatever i want it to be a memory-access, and not hibernate doing selects. I have done this:

    <class name="Blabla" table="VIT_BLABLA" mutable="false">
    <cache usage="read-only"/>

    but i see in logs that hibernate is still doing selects (show_sql=true) even with getHibernateTemplate().loadAll(). any suggestions appreciated

    thanks
    tom

  2. #2
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    There is a seperate setting for caching collections. Check hibernate docs, I cannot remember them off hand

    Also, be aware that if you do cache collections, hibernate *probably* (how else could it work?) will drop the collection cache as soon as the table is modified.

  3. #3
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    Very good example are found inside Spring samples and javadocs.

    Quote from LocalSessionFactoryBean:

    setEntityCacheStrategies

    public void setEntityCacheStrategies(Properties entityCacheStrategies)

    Specify the cache strategies for entities (persistent classes or named entities). This configuration setting corresponds to the <class-cache> entry in the "hibernate.cfg.xml" configuration format.

    For example:

    <property name="entityCacheStrategies">
    <props>
    <prop key="com.mycompany.Customer">read-write
    <prop key="com.mycompany.Product">read-only
    </props>
    </property>

    Parameters:
    entityCacheStrategies - properties that define entity cache strategies, with class names as keys and cache concurrency strategies as values
    See Also:
    Configuration.setCacheConcurrencyStrategy(String, String)
    setCollectionCacheStrategies

    public void setCollectionCacheStrategies(Properties collectionCacheStrategies)

    Specify the cache strategies for persistent collections (with specific roles). This configuration setting corresponds to the <collection-cache> entry in the "hibernate.cfg.xml" configuration format.

    For example:

    <property name="collectionCacheStrategies">
    <props>
    <prop key="com.mycompany.Order.items">read-only
    </props>
    </property>

    Parameters:
    collectionCacheStrategies - properties that define collection cache strategies, with collection roles as keys and cache concurrency strategies as values
    See Also:
    Configuration.setCollectionCacheConcurrencyStrateg y(String, String)

    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

Similar Threads

  1. Share cache manager with hibernate
    By scesbron in forum Data
    Replies: 11
    Last Post: Jan 3rd, 2011, 12:28 PM
  2. Replies: 2
    Last Post: Aug 11th, 2005, 09:22 AM
  3. Loosing my SecureContext
    By sklakken in forum Security
    Replies: 3
    Last Post: Jul 21st, 2005, 01:44 PM
  4. Replies: 8
    Last Post: Jan 22nd, 2005, 04:31 AM
  5. Replies: 3
    Last Post: Nov 19th, 2004, 07:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •