Olá Pessoas boa noite.
Estou com um problema que não estou encontrando.
Crie um projeto usando o VRaptor 4 e Postgres, pois no momento que eu salvo as informações o console não e apresenta nenhum erro, mais ao fazer um select na base de dados as informações não estão aparecendo.
Minha Tela:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Cadastro de Usuario</title>
</head>
<body>
<div>
<h1>Adicionando Usuario</h1>
<form action="<c:url value='/usuario/adiciona'/>" method="post">
Nome: <input type="text" name="usuario.nome" value="${usuario.nome}"/><br/>
Login: <input type="text" name="usuario.login" value="${usuario.login}"/><br/>
Senha: <input type="password" name="usuario.senha" value="${usuario.senha}"/><br/>
E-mail <input type="text" name="usuario.email" value="${usuario.email}"/><br/>
<button type="submit">Adiciona</button>
</form>
<c:if test="${not empty errors}">
<div>
<c:forEach var="error" items="${errors}">
${error.message}<br />
</c:forEach>
</div>
</c:if>
${mensagem}
</div>
</body>
</html>
Meu Persistence:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="default">
<!-- Implementação do JPA, no nosso caso Hibernate -->
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<!-- Aqui são listadas todas as classe marcadas com @Entity -->
<class>br.com.pagga.chamado.model.Usuario</class>
<properties>
<property name="javax.persistence.jdbc.driver"
value="org.postgresql.Driver" />
<property name="javax.persistence.jdbc.url"
value="jdbc:postgresql://localhost:5432/chamados" />
<property name="javax.persistence.jdbc.user"
value="chamados" />
<property name="javax.persistence.jdbc.password"
value="chamado" />
<!-- Configurações do hibernate -->
<property name="hibernate.dialect"
value="org.hibernate.dialect.PostgreSQLDialect" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.format_sql" value="false" />
</properties>
</persistence-unit>
</persistence>
Minha UsuarioDAO:
import javax.inject.Inject;
import javax.persistence.EntityManager;
import br.com.pagga.chamado.model.Usuario;
public class UsuarioDAO {
private final EntityManager em;
@Inject
public UsuarioDAO(EntityManager em) {
this.em = em;
}
@Deprecated
public UsuarioDAO() {
this(null);
}
public void save(Usuario usuario) {
if ( usuario.getId() == null || usuario.getId() == 0 )
em.persist(usuario);
else
em.merge(usuario);
em.getTransaction().commit();
}
}
Meu UsuarioController:
import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.validator.Validator;
import br.com.pagga.chamado.DAO.UsuarioDAO;
import br.com.pagga.chamado.model.Usuario;
@Controller
public class UsuarioController {
private final UsuarioDAO dao;
private final Result result;
private final Validator validator;
@Inject
public UsuarioController(UsuarioDAO dao, Result result, Validator validator) {
this.dao = dao;
this.result = result;
this.validator = validator;
}
@Deprecated
public UsuarioController() {
this(null,null,null);
}
@Get("/usuario/")
public void formulario() {
}
@Post
public void adiciona(Usuario usuario) {
dao.save(usuario);
result.redirectTo(this).formulario();
}
}
Minha Classe Modelo:
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
@Entity
@Table(name = "usuario")
public class Usuario {
@Id
@SequenceGenerator(name = "usuario_id_usuari_usr_seq", sequenceName = "usuario_id_usuari_usr_seq", initialValue = 1, allocationSize = 1)
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="usuario_id_usuari_usr_seq")
@Column(name = "id_usuari_usr")
private Integer id;
@Column(name = "nm_usuari_usr")
private String nome;
@Column(name = "nm_ulogin_usr")
private String login;
@Column(name = "cd_usenha_usr")
private String senha;
@Column(name = "nm_uemail_usr")
private String email;
public Usuario(String nome, String login, String senha, String email) {
this.nome = nome;
this.login = login;
this.senha = senha;
this.email = email;
}
public Usuario() {
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getSenha() {
return senha;
}
public void setSenha(String senha) {
this.senha = senha;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
Meu web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>chamado</display-name>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>messages</param-value>
</context-param>
<listener>
<listener-class>org.jboss.weld.environment.servlet.Listener
</listener-class>
</listener>
<resource-ref>
<description>Connection Pool</description>
<res-ref-name>jdbc/chamado</res-ref-name>
<res-type>javax.sql.Datasource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
Meu Container no Tomcat:
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource auth="Container" driverClassName="org.postgresql.Driver" maxActive="20" maxIdle="5" maxWait="-1" name="jdbc/chamado" password="chamado" type="javax.sql.DataSource" url="jdbc:postgresql://localhost:5432/chamados" username="chamados"/>
</GlobalNamingResources>
Meu pom.xml
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>br.com.caelum</groupId>
<artifactId>vraptor</artifactId>
<version>4.2.0.Final</version>
</dependency>
<!-- Dependencia do VRaptor que cuida da criação e DI da EntityManager
e EntityManagerFactory -->
<dependency>
<groupId>br.com.caelum.vraptor</groupId>
<artifactId>vraptor-jpa</artifactId>
<version>4.0.5</version>
</dependency>
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet-core</artifactId>
<version>3.0.5.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-core-impl</artifactId>
<version>3.0.5.Final</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.18.1-GA</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator-cdi</artifactId>
<version>5.4.2.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.3.7.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.3.7.Final</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-agroal</artifactId>
<version>5.3.7.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.3.7.Final</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Por Favor me ajudem.
Desde já agradeço.