Announcement Announcement Module
Collapse
No announcement yet.
Hibernate with L2 cache Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hibernate with L2 cache

    I have 2nd level cache working with hibernate.
    To enable Query Cache with hibernate without spring I do the following:

    List blogs = sess.createQuery("from Blog blog where blog.blogger = :blogger")
    .setEntity("blogger", blogger)
    .setMaxResults(15)
    .setCacheable(true)
    .setCacheRegion("frontpages")
    .list();

    I have tried to achieve the same thing with Spring API.
    I have added the following line to the hibernate props in applicationContext.xml:

    <prop key="hibernate.cache.use_query_cache">true</prop>

    and compiled the code including the bit below:

    List blogs = getSession().createQuery("from Blog blog where blog.blogger = :blogger")
    .setEntity("blogger", blogger)
    .setMaxResults(15)
    .setCacheable(true)
    .setCacheRegion("frontpages")
    .list();


    It gave the warning:

    01-Dec-2005 15:44:14 org.hibernate.jdbc.ConnectionManager finalize
    WARNING: unclosed connection, forgot to call close() on your session?

    Then I tried to add to the above code (with catching SQLException etc,of course):
    getSession().connection().close();

    And I get the following Warning:

    01-Dec-2005 15:44:14 org.hibernate.jdbc.Con
    WARNING: finalizing with closed connection

    Am I doing something wrong?
    Please enlighten

  • #2
    Hibernate with L2 cache

    I have tried this and it does not give me warnings but I still do not understand why it did not wotk with previous attempts

    Session session= getSession();
    List blogs = sessioncreateQuery("from Blog blog where blog.blogger = :blogger")
    .setEntity("blogger", blogger)
    .setMaxResults(15)
    .setCacheable(true)
    .setCacheRegion("frontpages")
    .list();
    session.disconnect();

    Comment


    • #3
      I also noticed this when I added query caching to a query last week. I'd also appreciate any clarification of the need to explicitly close sessions/connections in such a situation, or if this is just a spurious warning (sort of what I've been assuming).

      Jonny

      Comment

      Working...
      X