I use JPA + Hibernate + Spring for simple job. I wrote next modules:
Service:
@Autowired
private VolMng volMng;
@Service
public class Dist {
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public void gen() {
MeterLog mLog = em.find(MeterLog.class, 3625190);
Lst volTp = lstMng.findByCD("Fact Vol");
Vol vol = new Vol((MeterLog) mLog, volTp, 7777.77d);
volMng.add(vol);
//point-1:
for (Vol a : mLog.getVol()) {
System.out.println("found="+a.getId()+" vol="+a.getVol1());
}
...
...
Service:
@Service
public class VolMngImpl implements VolMng {
@Autowired
private VolDAO vDao;
public void add(Vol vol) {
vDao.add(vol);
}
}
DAO:
@Repository
public class VolDAOImpl implements VolDAO {
@PersistenceContext
private EntityManager em;
public void add(Vol vol) {
em.persist(vol);
}
}
I am trying to add some records to child entity Vol.
But after volMng.add(vol) at point-1 I don't see any added records (child entities). Why?
upd
Of course I see these records after end of transaction, but why I can't do it before??? They must be in memory cache...
upd2
My spring.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cache="http://www.springframework.org/schema/cache"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.2.xsd">
<!-- *******************************
***** CACHE CONFIGURATION *****
******************************* -->
<cache:annotation-driven cache-manager="cacheManager" />
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
<property name="cacheManager" ref="ehcache"/>
</bean>
<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath:ehcache.xml"/>
<property name="shared" value="true"/>
</bean>
<bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource" destroy-method="close">
<property name="URL" value="jdbc:oracle:thin:@192.168.1.1:1521:DEV" />
<property name="user" value="ora"/>
<property name="password" value="ora"/>
<property name="connectionCachingEnabled" value="true"/>
</bean>
<bean
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
id="entityManagerFactory">
<property name="dataSource" ref="dataSource" />
</bean>
<context:component-scan base-package="com.ric.bill" />
<context:component-scan base-package="com.ric.bill.dao.impl" />
<context:component-scan base-package="com.ric.bill.mm.impl" />
<bean class="org.springframework.orm.jpa.JpaTransactionManager"
id="transactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven mode="proxy" transaction-manager="transactionManager"/>
<context:spring-configured />
<context:annotation-config />
</beans>