I can't seem to make the cache work properly
Here's my
persistence.xmlCode:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="test.persistence">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.myapp.datamodel.OrderDetail</class>
<class>com.myapp.datamodel.OrderDetailAttachment</class>
<class>com.myapp.datamodel.OrderHeader</class>
<class>com.myapp.datamodel.OrderHeaderAttachment</class>
<exclude-unlisted-classes />
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect" />
<property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.connection.username" value="......" />
<property name="hibernate.connection.password" value="........" />
<property name="hibernate.connection.url" value="........." />
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.jbc2.MultiplexedJBossCacheRegionFactory" />
</properties>
</persistence-unit>
</persistence>
application-context.xmlCode:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"
default-autowire="byName">
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="test.persistence" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven />
<context:annotation-config />
<context:component-scan base-package="com.myapp" />
</beans>
Test classCode:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/application-context.xml")
@Transactional
public class OrderManagerTest {
@Autowired
private OrderManager orderManager;
@Test
public void test1() {
OrderHeader orderHeader = orderManager.getOrderHeader(new BigDecimal(557916160));
}
@Test
public void test2() {
OrderHeader orderHeader = orderManager.getOrderHeader(new BigDecimal(557916160));
}
}
When running the test, I see in the console the SQL statement executed twice, although I would have expected that the object was already cached.
Thank you