-
May 23rd, 2009, 08:43 AM
#1
JPA + Spring + Oracle DB in standalone Env: Inserts are not getting commited
Dao
There is a Dao class with DDL and DML operations
eg. Class DataAccessDao {
@Transactional(propagation = Propagation.REQUIRED, rollbackFor=Exception.class)
public SampleBean insert(SampleBean record) {
...
}
}
persistence.xml lists the entities and defines the following properties
<persistence-unit name="dstest" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceP rovider</provider>
<class>sample.entity</class>
...
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="eclipselink.jdbc.url" value="jdbc:oracle:thin:@localhost:1521:ORCL"/>
<property name="eclipselink.jdbc.user" value="ds"/>
<property name="eclipselink.jdbc.password" value="ds"/>
<property name="eclipselink.jdbc.driver" value="oracle.jdbc.OracleDriver"/>
<property name="eclipselink.jdbc.platform" value="org.eclipse.persistence.platform.database.o racle.OraclePlatform" />
<property name="eclipselink.logging.level" value="FINEST" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
</properties>
</persistence-unit>
Spring config
Setting up the entitymanager and transaction manager as follows
<tx:annotation-driven transaction-manager="txManager" order="200"/>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityMana gerFactoryBean">
<property name="persistenceUnitName" value="dstest"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.EclipseL inkJpaVendorAdapter">
<property name="showSql" value="true"/>
<property name="generateDdl" value="true"/>
<property name="database" value="ORACLE"/>
</bean>
</property>
</bean>
<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionM anager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<bean id="DataAccessDao" class="mypackage.DataAccessDao ">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
The execution goes through fine, but the issue is when insert() in the DataAccessDao gets called it does not get committed into the DB!
Any thoughts/pointers appreciated
-
May 23rd, 2009, 03:50 PM
#2
Please use [ code][/code ] tags when posting code, that way it remains readable. How are you loading the beans? Are you using a BeanFactory or an ApplicationContext? And what is your insert method doing?
-
May 26th, 2009, 09:21 AM
#3
Applicationcontext is the method used to load the beans in the spring container and the insert method is inserting a row into the database.
PS:
1. There are 2 persistence units defined in the persistence.xml one for the container env and the other for the standalone env ( testing ). In the container environment the code is functional but, in the standalone env, am having issues with the commit of the record.
2. <aop:aspectj-autoproxy/> is enabled
3. Will use the code tags in future
Thanks
Chandan
-
May 26th, 2009, 09:27 AM
#4
Not sure why you would need 2 different units you should be able to work with one and only replace the infrastructure beans which differ (i.e. a JtaTransactionManager instead of a JpaTransactionManager etc.). I suspect it works because of the container managed transaction and that it completly bypassed the spring configured transactions.
Enable classproxying for both your aop:aspectj-autoproxy and the tx:annotation-driven, your dao's dont seem to implement an interface (which is a best practice!) which is what the default proxying mechanism expects.
Also I would strive to eliminate the need for 2 persistence unit because now your tests basically say nothing about your live situation (you use 2 different configuration sets) and it is also quite hard to do full integration tests. Next to that do you really need a container managed transaction?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules