I am using Spring + EclipseLink 2 to manage the entity in the Derby database. Selecting an object from db works fine, but when I try to save it, nothing happens. The program runs correctly, and no exceptions are thrown. I probably did something wrong as I am not familiar with Spring, thanks for your comments and suggestions :)
ServerDaoDb Method:
@Transactional public void addServer(Server server) { EntityManager em = emf.createEntityManager(); emf.createEntityManager().persist(server); em.close(); }
Application Context:
... <tx:annotation-driven /> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean"> <property name="persistenceUnitName" value="SpringPratiquePU" /> </bean> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory"/> </bean> <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /> <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
Persistence.xml:
<persistence-unit name="SpringPratiquePU" transaction-type="RESOURCE_LOCAL"> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> <class>net.athom.spring.examples.models.eas.Server</class> <class>net.athom.spring.examples.models.eas.Node</class> <properties> <property name="eclipselink.target-database" value="DERBY"/> <property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/SpringPratique"/> <property name="javax.persistence.jdbc.password" value="clem"/> <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/> <property name="javax.persistence.jdbc.user" value="clem"/> </properties> </persistence-unit> </persistence>
Trace debugging:
DEBUG JpaTransactionManager:365 - Creating new transaction with name [net.athom.spring.examples.service.impl.ServerManagerImpl.addServer]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; '' [EL Info]: 2010-10-29 15:33:27.443--ServerSession(14894886)--EclipseLink, version: Eclipse Persistence Services - 2.0.2.v20100323-r6872 [EL Info]: 2010-10-29 15:33:28.606--ServerSession(14894886)--file:/C:/netbeanProject/SpringPratique/src/_SpringPratiquePU login successful 15:33:28,893 DEBUG JpaTransactionManager:323 - Opened new EntityManager [ org.eclipse.persistence.internal.jpa.EntityManagerImpl@1779885 ] for JPA transaction 15:33:28,951 DEBUG DefaultListableBeanFactory:242 - Returning cached instance of singleton bean 'transactionManager' 15:33:28,952 DEBUG JpaTransactionManager:286 - Found thread-bound EntityManager [ org.eclipse.persistence.internal.jpa.EntityManagerImpl@1779885 ] for JPA transaction 15:33:28,953 DEBUG JpaTransactionManager:470 - Participating in existing transaction 15:33:29,266 DEBUG JpaTransactionManager:752 - Initiating transaction commit 15:33:29,267 DEBUG JpaTransactionManager:462 - Committing JPA transaction on EntityManager [ org.eclipse.persistence.internal.jpa.EntityManagerImpl@1779885 ] 15:33:29,268 DEBUG JpaTransactionManager:548 - Closing JPA EntityManager [ org.eclipse.persistence.internal.jpa.EntityManagerImpl@1779885 ] after transaction 15:33:29,308 DEBUG EntityManagerFactoryUtils:328 - Closing JPA EntityManager
source share