Problemas ao Persistir Postgres

0 respostas
Cristofe

Bom dia Pessoal,

estou tendo problemas ao persistir no banco Postgres. Ao preencher o formulário realizo o insert mas somente o campo id é incrementado os demais nao. Segue banco:

-- Table: usuario

-- DROP TABLE usuario;

CREATE TABLE usuario
(
  ativo integer,
  permissao integer,
  passwd text,
  "login" text,
  cod_usuario serial NOT NULL,
  nome character(10),
  CONSTRAINT cod_usuario PRIMARY KEY (cod_usuario)
)
WITH (
  OIDS=FALSE,
  autovacuum_enabled=true
);
ALTER TABLE usuario OWNER TO postgres;
GRANT ALL ON TABLE usuario TO public;
GRANT ALL ON TABLE usuario TO postgres;
GRANT SELECT("login"), UPDATE("login"), INSERT("login"), REFERENCES("login") ON usuario TO public;

Minha entity é :

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ifrr.entity;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

/**
 *
 * @author cristofe.rocha
 */
@Entity
@Table(name = "usuario")
@NamedQueries({
    @NamedQuery(name = "Usuario.findAll", query = "SELECT u FROM Usuario u"),
    @NamedQuery(name = "Usuario.findByAtivo", query = "SELECT u FROM Usuario u WHERE u.ativo = :ativo"),
    @NamedQuery(name = "Usuario.findByPermissao", query = "SELECT u FROM Usuario u WHERE u.permissao = :permissao"),
    @NamedQuery(name = "Usuario.findByPasswd", query = "SELECT u FROM Usuario u WHERE u.passwd = :passwd"),
    @NamedQuery(name = "Usuario.findByLogin", query = "SELECT u FROM Usuario u WHERE u.login = :login"),
    @NamedQuery(name = "Usuario.findByCodUsuario", query = "SELECT u FROM Usuario u WHERE u.codUsuario = :codUsuario"),
    @NamedQuery(name = "Usuario.findByNome", query = "SELECT u FROM Usuario u WHERE u.nome = :nome")})
public class Usuario implements Serializable {

    private static final long serialVersionUID = 1L;
    @Column(name = "ativo")
    private Integer ativo;
    @Column(name = "permissao")
    private Integer permissao;
    @Column(name = "passwd")
    private String passwd;
    @Column(name = "login")
    private String login;

    @Id
    @SequenceGenerator( name = "cod_seq", sequenceName = "cod_seq", allocationSize = 1 )
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator="cod_seq")
    @Column(name = "cod_usuario")
    private Integer codUsuario;

    @Column(name = "nome")
    private String nome;

    public Usuario() {
    }

    public Usuario(Integer codUsuario) {
        this.codUsuario = codUsuario;
    }

    public Integer getAtivo() {
        return ativo;
    }

    public void setAtivo(Integer ativo) {
        this.ativo = ativo;
    }

    public Integer getPermissao() {
        return permissao;
    }

    public void setPermissao(Integer permissao) {
        this.permissao = permissao;
    }

    public String getPasswd() {
        return passwd;
    }

    public void setPasswd(String passwd) {
        this.passwd = passwd;
    }

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public Integer getCodUsuario() {
        return codUsuario;
    }

    public void setCodUsuario(Integer codUsuario) {
        this.codUsuario = codUsuario;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (codUsuario != null ? codUsuario.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Usuario)) {
            return false;
        }
        Usuario other = (Usuario) object;
        if ((this.codUsuario == null && other.codUsuario != null) || (this.codUsuario != null && !this.codUsuario.equals(other.codUsuario))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "br.ifrr.entity.Usuario[codUsuario=" + codUsuario + "]";
    }
}

ao submeter o formulário recebo os seguinte logs:

11/04/2012 12:45:08 org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: .:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java
11/04/2012 12:45:08 org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8084
11/04/2012 12:45:08 org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1297 ms
11/04/2012 12:45:09 org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
11/04/2012 12:45:09 org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.26
11/04/2012 12:45:09 org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor manager.xml
11/04/2012 12:45:09 org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor ROOT.xml
11/04/2012 12:45:10 org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor usuario.xml
11/04/2012 12:45:11 com.sun.faces.config.ConfigureListener contextInitialized
INFO: Inicializando Mojarra 2.0.2 (FCS b10) para o contexto '/usuario'
11/04/2012 12:45:11 com.sun.faces.config.configprovider.BaseWebConfigResourceProvider getResources
AVISO: JSF1067: O recurso /WEB-INF/newfaces-config1.xml especificado pela opção de configuração javax.faces.CONFIG_FILES não pôde ser encontrado.  O recurso será ignorado.
11/04/2012 12:45:16 com.sun.faces.config.ConfigureListener$WebConfigResourceMonitor$Monitor <init>
INFO: Monitoring jndi:/localhost/usuario/WEB-INF/faces-config.xml for modifications
11/04/2012 12:45:16 org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8084
11/04/2012 12:45:16 org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
11/04/2012 12:45:16 org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/101  config=null
11/04/2012 12:45:16 org.apache.catalina.startup.Catalina start
INFO: Server startup in 7899 ms
11/04/2012 12:45:20 com.sun.faces.renderkit.html_basic.HtmlBasicRenderer getForComponent
AVISO: Não foi possível encontrar o componente com a ID Nome na exibição.
11/04/2012 12:45:20 com.sun.faces.renderkit.html_basic.HtmlBasicRenderer getForComponent
AVISO: Não foi possível encontrar o componente com a ID Login na exibição.
2 [http-8084-7] INFO org.hibernate.cfg.annotations.Version - Hibernate Annotations 3.3.1.GA
58 [http-8084-7] INFO org.hibernate.cfg.Environment - Hibernate 3.2.5
62 [http-8084-7] INFO org.hibernate.cfg.Environment - hibernate.properties not found
63 [http-8084-7] INFO org.hibernate.cfg.Environment - Bytecode provider name : cglib
85 [http-8084-7] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
238 [http-8084-7] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
238 [http-8084-7] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
536 [http-8084-7] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null
679 [http-8084-7] INFO org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: br.ifrr.entity.Usuario
699 [http-8084-7] INFO org.hibernate.cfg.annotations.QueryBinder - Binding Named query: Usuario.findAll => SELECT u FROM Usuario u
699 [http-8084-7] INFO org.hibernate.cfg.annotations.QueryBinder - Binding Named query: Usuario.findByAtivo => SELECT u FROM Usuario u WHERE u.ativo = :ativo
699 [http-8084-7] INFO org.hibernate.cfg.annotations.QueryBinder - Binding Named query: Usuario.findByPermissao => SELECT u FROM Usuario u WHERE u.permissao = :permissao
699 [http-8084-7] INFO org.hibernate.cfg.annotations.QueryBinder - Binding Named query: Usuario.findByPasswd => SELECT u FROM Usuario u WHERE u.passwd = :passwd
699 [http-8084-7] INFO org.hibernate.cfg.annotations.QueryBinder - Binding Named query: Usuario.findByLogin => SELECT u FROM Usuario u WHERE u.login = :login
699 [http-8084-7] INFO org.hibernate.cfg.annotations.QueryBinder - Binding Named query: Usuario.findByCodUsuario => SELECT u FROM Usuario u WHERE u.codUsuario = :codUsuario
699 [http-8084-7] INFO org.hibernate.cfg.annotations.QueryBinder - Binding Named query: Usuario.findByNome => SELECT u FROM Usuario u WHERE u.nome = :nome
806 [http-8084-7] INFO org.hibernate.cfg.annotations.EntityBinder - Bind entity br.ifrr.entity.Usuario on table usuario
934 [http-8084-7] INFO org.hibernate.cfg.AnnotationConfiguration - Hibernate Validator not found: ignoring
1142 [http-8084-7] INFO org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
1142 [http-8084-7] INFO org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 20
1142 [http-8084-7] INFO org.hibernate.connection.DriverManagerConnectionProvider - autocommit mode: false
1168 [http-8084-7] INFO org.hibernate.connection.DriverManagerConnectionProvider - using driver: org.postgresql.Driver at URL: jdbc:postgresql://localhost:5432/aluno
1168 [http-8084-7] INFO org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=postgres, password=****}
1868 [http-8084-7] INFO org.hibernate.cfg.SettingsFactory - RDBMS: PostgreSQL, version: 9.0.3
1868 [http-8084-7] INFO org.hibernate.cfg.SettingsFactory - JDBC driver: PostgreSQL Native Driver, version: PostgreSQL 8.3 JDBC3 with SSL (build 603)
1980 [http-8084-7] INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.PostgreSQLDialect
1987 [http-8084-7] INFO org.hibernate.transaction.TransactionFactoryFactory - Using default transaction strategy (direct JDBC transactions)
1990 [http-8084-7] INFO org.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
1990 [http-8084-7] INFO org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
1991 [http-8084-7] INFO org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled
1991 [http-8084-7] INFO org.hibernate.cfg.SettingsFactory - JDBC batch size: 15
1991 [http-8084-7] INFO org.hibernate.cfg.SettingsFactory - JDBC batch updates for versioned data: disabled
2000 [http-8084-7] INFO org.hibernate.cfg.SettingsFactory - Scrollable result sets: enabled
2000 [http-8084-7] INFO org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): disabled
2000 [http-8084-7] INFO org.hibernate.cfg.SettingsFactory - Connection release mode: auto
2001 [http-8084-7] INFO org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1
2001 [http-8084-7] INFO org.hibernate.cfg.SettingsFactory - Generate SQL with comments: disabled
2001 [http-8084-7] INFO org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled
2001 [http-8084-7] INFO org.hibernate.cfg.SettingsFactory - Order SQL inserts for batching: disabled
2001 [http-8084-7] INFO org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
2004 [http-8084-7] INFO org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
2004 [http-8084-7] INFO org.hibernate.cfg.SettingsFactory - Query language substitutions: {}
2004 [http-8084-7] INFO org.hibernate.cfg.SettingsFactory - JPA-QL strict compliance: disabled
2004 [http-8084-7] INFO org.hibernate.cfg.SettingsFactory - Second-level cache: enabled
2004 [http-8084-7] INFO org.hibernate.cfg.SettingsFactory - Query cache: disabled
2004 [http-8084-7] INFO org.hibernate.cfg.SettingsFactory - Cache provider: org.hibernate.cache.NoCacheProvider
2004 [http-8084-7] INFO org.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: disabled
2004 [http-8084-7] INFO org.hibernate.cfg.SettingsFactory - Structured second-level cache entries: disabled
2011 [http-8084-7] INFO org.hibernate.cfg.SettingsFactory - Statistics: disabled
2011 [http-8084-7] INFO org.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled
2012 [http-8084-7] INFO org.hibernate.cfg.SettingsFactory - Default entity-mode: pojo
2012 [http-8084-7] INFO org.hibernate.cfg.SettingsFactory - Named query checking : enabled
2152 [http-8084-7] INFO org.hibernate.impl.SessionFactoryImpl - building session factory
2532 [http-8084-7] INFO org.hibernate.impl.SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured

Estou meio perdido. Alguem pode me ajudar?
Segue o form:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:head>
        <title>Cadastro de usuario</title>
    </h:head>
    <h:body>

        <h:form id="cadastro">
            <h:messages/>
            <h:graphicImage value="img/logo_ifrr.jpg"/>
            <p:panel header="Cadastro de usuarios">
                <h:panelGrid>
                    <h:column>
                        <h:outputLabel value="Nome:" for="Nome"/>
                        <h:inputText value="#{usuarioBean.usuario.nome}" required="true" maxlength="40" id="nome" label="nome" requiredMessage="Informe o Nome do Usuario.">
                            <f:validateLength maximum="40" minimum="1"/>
                        </h:inputText>
                    </h:column>
                    <h:column>
                        <h:outputLabel value="Login:" for="Login"/>
                        <h:inputText value="#{usuarioBean.usuario.login}" required="true" maxlength="15" id="login" label="login" requiredMessage="Informe o Login do Usuario Max 15 e Min 6 Digitos.">
                            <f:validateLength maximum="15" minimum="6"/>
                        </h:inputText>
                    </h:column>
                    <h:column>
                        <h:outputLabel value ="Senha:"/>
                        <h:inputSecret value="#{usuarioBean.usuario.passwd}" required="true" maxlength="6" id="secret" requiredMessage="Informe a Senha do usuario Max 6 e Min 6 Digitos." >
                            <f:validateLength maximum="8" minimum="6"/>
                        </h:inputSecret>
                    </h:column>
                    <h:column>
                        <h:outputLabel value="confimar Senha:"/>
                        <h:inputSecret value="#{usuarioBean.confirmaSenha}" required="true" maxlength="6" id="secret2" requiredMessage="Informe a Senha do usuario Max 6 e Min 6 Digitos." >
                            <f:validateLength maximum="8" minimum="6"/>
                        </h:inputSecret>
                    </h:column>
                    <h:column>
                        <h:outputLabel value="Permissao"/>
                        <h:selectOneMenu value="#{usuarioBean.usuario.permissao}" id="permissao">
                            <f:selectItem itemValue="2" itemLabel="Tecnico"/>
                            <f:selectItem itemValue="3" itemLabel="Professor"/>
                            <f:selectItem itemValue="1" itemLabel="Diretor"/>
                            <f:selectItem itemValue="3" itemLabel="Coordenador"/>
                            <f:selectItem itemValue="3" itemLabel="Administrador"/>
                        </h:selectOneMenu>
                    </h:column>
                    <h:column>
                        <h:commandButton value="Salvar" action="#{usuarioBean.novo}"/>
                    </h:column>
                </h:panelGrid>
            </p:panel>
        </h:form>
    </h:body>
</html>

Segue meu ManagerBean

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ifrr.usuario;

import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.bean.*;
import javax.faces.context.FacesContext;
import br.ifrr.entity.*;

/**
 *
 * @author Cristofe Rocha
 */
@ManagedBean(name = "usuarioBean")
@RequestScoped
public class UsuarioBean {

    private Usuario usuario = new Usuario();
    private String confirmaSenha;
    private List<Usuario> lista;

    public String novo() {
        this.usuario = new Usuario();
        UsuarioRN usuarioRN = new UsuarioRN();
        usuarioRN.novo(this.usuario);
        return "cadUsuario";
    }

    public String salvar() {
        FacesContext context = FacesContext.getCurrentInstance();

        String senha = this.usuario.getPasswd();
        if (!senha.equals(this.confirmaSenha)) {
            FacesMessage facesMessage = new FacesMessage("A senhas sao diferentes");
            context.addMessage(null, facesMessage);
            return null;
        }
        UsuarioRN usuarioRN = new UsuarioRN();
        usuarioRN.salvar(this.usuario);
        return "cadUsuario";

    }

    public String getConfirmaSenha() {
        return confirmaSenha;
    }

    public void setConfirmaSenha(String confirmaSenha) {
        this.confirmaSenha = confirmaSenha;
    }

    public Usuario getUsuario() {
        return usuario;
    }

    public void setUsuario(Usuario usuario) {
        this.usuario = usuario;
    }
}
Criado 11 de abril de 2012
Respostas 0
Participantes 1