Amigos, estou estudando a integração de Spring+JPA e estou tendo o seguinte problema:
servlet-context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-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/task http://www.springframework.org/schema/task/spring-task-3.0.xsd">
<mvc:annotation-driven/>
<context:component-scan base-package="br.com.estudoSpringMVC.tarefas"/>
<bean id="oracleDataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@localhost:1521:xe"/>
<property name="username" value="TAREFA"/>
<property name="password" value="TAREFA"/>
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="oracleDataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<tx:annotation-driven />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="views/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
persistence.xml:
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="tarefas" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>br.com.estudoSpringMVC.tarefas.entidade.Tarefa</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit>
</persistence>
controller:
package br.com.estudoSpringMVC.tarefas.controller;
import br.com.estudoSpringMVC.tarefas.entidade.Tarefa;
import br.com.estudoSpringMVC.tarefas.hibernate.TarefaDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* Created by IntelliJ IDEA.
* Date: 03/07/13
* Time: 14:35
* To change this template use File | Settings | File Templates.
*/
@Transactional
@Controller
public class TarefasController {
@Autowired
private TarefaDao tarefaDao;
@RequestMapping("novaTarefa")
public String novaTarefa() {
return "tarefa/formulario";
}
@RequestMapping("adicionarTarefa")
public String inserir(Tarefa tarefa) {
this.tarefaDao.inserir(tarefa);
return "tarefa/tarefa-adicionada";
}
}
dao:
package br.com.estudoSpringMVC.tarefas.hibernate;
import br.com.estudoSpringMVC.tarefas.entidade.Tarefa;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
/**
* Created by IntelliJ IDEA.
* Date: 04/07/13
* Time: 09:58
* To change this template use File | Settings | File Templates.
*/
@Repository
public class TarefaDao {
@PersistenceContext
private EntityManager manager;
public void inserir(Tarefa tarefa) {
manager.persist(tarefa);
}
}
Estou usando Tocat 7. Quando faço o deploy e rodo a aplicação, se chamo o metodo inserir apenas recebo de msg no console o seguinte:
Hibernate:
select
hibernate_sequence.nextval
from
dual
E a persistencia não é feita no banco. Alguém poderia dar uma luz de resolver esse problema?