Thursday, 22 August 2013

Spring application doesn't appear to be persisting data

Spring application doesn't appear to be persisting data

I'm trying to write something into my database but it's not working
despite it reporting "Successfully completed request". After the success
everything seems to work fine and my controller redirects me correctly.
Debug
DEBUG a.d.p.payment.PaymentServiceImpl - Requesting to persist new
user'max_test@test.com'.
DEBUG a.d.p.payment.model.PaymentDAOImpl - Persisting
com.app.payment.model.PaymentUser@86ceb985.
DEBUG
o.s.o.j.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler -
Creating new EntityManager for shared EntityManager invocation
DEBUG org.hibernate.impl.SessionImpl - opened session at timestamp:
13771737739
DEBUG o.h.e.def.AbstractSaveEventListener - delaying identity-insert due
to no transaction in progress
DEBUG o.s.o.jpa.EntityManagerFactoryUtils - Closing JPA EntityManager
DEBUG o.s.b.f.s.DefaultListableBeanFactory - Invoking afterPropertiesSet()
on bean with name 'redirectForm'
DEBUG o.s.web.servlet.DispatcherServlet - Rendering view
[org.springframework.web.servlet.view.JstlView: name 'redirectForm'; URL
[/WEB-INF/jsp/redirectForm.jsp]] in DispatcherServlet with name 'payment'
DEBUG o.s.web.servlet.view.JstlView - Forwarding to resource
[/WEB-INF/jsp/redirectForm.jsp] in InternalResourceView 'redirectForm'
DEBUG o.s.web.servlet.DispatcherServlet - Successfully completed request
appContext.xml (root context)
<context:annotation-config />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="username" value="test" />
<property name="password" value="test" />
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<!--payment_test is the name of the schema -->
<property name="url" value="jdbc:mysql://test1.com:3306/payment_test" />
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="payment" />
<property name="persistenceUnitManager">
<bean
class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager"
>
<property name="defaultDataSource" ref="dataSource" />
</bean>
</property>
<property name="jpaVendorAdapter">
<bean
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true" />
<property name="generateDdl" value="true" />
<property name="databasePlatform"
value="org.hibernate.dialect.MySQLDialect" />
</bean>
</property>
</bean>
<context:component-scan base-package="com.app.payment" />
<context:annotation-config />
<!-- Auto scan the components -->
<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager" />
<tx:annotation-driven />
PaymentUser
@Entity
@Table(name="PaymentUser")
public class PaymentUser {
@Id
@GeneratedValue
private int id;
...
}
PaymentService
@Transactional("transactionManager")
@Service()
public class PaymentServiceImpl implements PaymentService {
@Autowired
private PaymentDAO paymentDAO;
// ... service methods
}
Payment DAO
@Repository()
public class PaymentDAOImpl implements PaymentDAO {
//@PersistenceContext(unitName="payment")
@PersistenceContext()
EntityManager em;
}
It seems like it doesn't even start a transaction. Hope thats enough info
for somebody to help me. Thanks for any help.

No comments:

Post a Comment