javaeetutorial
  1. javaeetutorial
  2. JAVAEETUTORIAL-269

Incorrect tutorial example for passing CacheStoreMode & CacheRetrieveMode

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: examples
    • Labels:
      None

      Description

      There is a link on Java EE6 tutorial named as 'Specifying the Cache Mode Settings to Improve Performance'. The url is : http://docs.oracle.com/javaee/6/tutorial/doc/gkjjj.html.
      Here an example is mentioned under sub-heading 'Setting the Cache Retrieval or Store Mode'. The example is as follows -

      EntityManager em = ...;
      em.setProperty("javax.persistence.cache.storeMode", "BYPASS");

      ...............

      EntityManager em = ...;
      Map<String, Object> props = new HashMap<String, Object>();
      props.put("javax.persistence.cache.retrieveMode", "BYPASS");
      String personPK = ...;
      Person person = em.find(Person.class, personPK, props);

      This will fail with hibernate-entitymanager
      In both above examples, setting string "BYPASS" against property "javax.persistence.cache.storeMode" will always throw Runtime Exception i.e ClassCastException stating String cannot be converted to Enum. This is due to the internal code of Hibernate class org.hibernate.ejb.AbstractEntityManagerImpl that directly casts object value to Enum without calling Enum.valueOf(String)

      For Hibernate users, it should be CacheStoreMode.BYPASS insted of "BYPASS".

        Activity

        Hide
        Kim Haase added a comment -

        The problem does not exist with GlassFish, the supported application server for the tutorial. Users of Hibernate will need to modify source code for their platform.

        Show
        Kim Haase added a comment - The problem does not exist with GlassFish, the supported application server for the tutorial. Users of Hibernate will need to modify source code for their platform.

          People

          • Assignee:
            jendrock
            Reporter:
            nkhattar
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: