Skip to Main Content

Integration

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

TopLink Essentials: Using spring session scope on the EntityManagerFactory

455640Dec 10 2007 — edited Apr 14 2008
Hi,

In one of our projects we are trying to utilize the 2nd level cache of TopLink Essentials. The server code is using the Spring (2.0.7) and is deployed to a web container. We are using a Java client and serializes every object between the client and the server.

When a client is started a lot of "static/common" data is read from the server. The first client started will therefor pay some extra performance cost, but additional clients should hopefully be able to perform better due to the cache. Most of the static data is accessed not using JPQL and should therefor not bypass the cache.

If we configure the EntityManagerFactory using default Spring scoping (singleton) it seems like we are not able to utilize the cache. We can see from the log files that each time a client is started a lot of SQL is executed towards the database (Oracle).
  <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="jpaVendorAdapter">
      <bean class="org.springframework.orm.jpa.vendor.TopLinkJpaVendorAdapter">
        <property name="showSql" value="false" />
        <property name="generateDdl" value="$repository{toplink.generateDdl}" />
        <property name="database" value="$repository{toplink.database}" />
      </bean>
    </property>
    <property name="jpaProperties">
      <props>
        <prop key="toplink.weaving">static</prop>
        <prop key="toplink.logging.level">FINEST</prop>
      </props>
    </property>
  </bean>
When we changes the scoping to spring session the behavior is very different. Then we can see that the first client generates a lot of SQL towards the database and pays a startup cost, while subsequently clients seems to be able to utilize the cache.
  <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" scope="session">
    <aop:scoped-proxy />
    <property name="dataSource" ref="dataSource" />
    <property name="jpaVendorAdapter">
      <bean class="org.springframework.orm.jpa.vendor.TopLinkJpaVendorAdapter">
        <property name="showSql" value="false" />
        <property name="generateDdl" value="$repository{toplink.generateDdl}" />
        <property name="database" value="$repository{toplink.database}" />
      </bean>
    </property>
    <property name="jpaProperties">
      <props>
        <prop key="toplink.weaving">static</prop>
        <prop key="toplink.logging.level">FINEST</prop>
      </props>
    </property>
  </bean>
Having read the documentation of the spring session scope I'm having a hard time explaining this behavior. As I understand it the EntityManagerFactory will be stored in the HTTP session resulting in a new EntityManagerFactory for each session. I cannot understand how this may result in that we are able to utilize the 2nd level cache? What are the relationship between the EntityManagerFactory and the 2nd level cache?

Is this an accepted way of configuring the EntityManagerFactory or will there be a downside?

I hope someone are able to explain this behavior for me:-)

Best regards,
Rune
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 12 2008
Added on Dec 10 2007
5 comments
4,526 views