Hello,
I'm trying to use support for JPA of spring with hibernate but I have a problem: The data is not stored in the database, the strange thing is that the dependency injection occurs without problems and no exception occurs.
My spring's configuration is:
Code:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
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">
<bean id="requestProcessAction" class="org.examples.action.RequestProcessAction" scope="prototype">
<property name="procesoDAO" ref="daoProceso"/>
</bean>
<!--JPA with Spring and Hibernate -->
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/database"/>
<property name="username" value="user"/>
<property name="password" value="pass"/>
</bean>
<bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="database" value="MYSQL" />
<property name="showSql" value="true" />
<property name="generateDdl" value="false" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<!-- DAOs -->
<bean id="daoProceso" class="org.examples.daoImpl.ProcesoDAOHibernateJPA"/>
</beans>
My DAO example is:
Code:
package org.examples.daoImpl;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.examples.dao.ProcesoDAO;
import org.examples.pojo.Proceso;
import org.springframework.stereotype.Repository;
@Repository
public class ProcesoDAOHibernateJPA implements ProcesoDAO{
@PersistenceContext
private EntityManager entityManager;
public void addProceso(Proceso proceso) {
System.out.println("Data: "+proceso.getNombre()+" "+proceso.getDescripcion());
entityManager.persist(proceso);
System.out.println("Test Entity Manager: "+entityManager.toString());
}
}
What could be the cause of this behavior? How I can fix it?
I hope someone can help me with this problem
Thanks in advance,