Não consigo persistir meu Objeto
Meu Formulário.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition template="/WEB-INF/template/layoutPadrao.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:o="http://omnifaces.org/ui">
<ui:define name="titulo">Cadastro de Fabricante</ui:define>
<ui:define name="corpo">
<f:metadata>
<f:viewParam name="fabricante" value="#{cadastroFabricanteBean.fabricante}" />
<f:viewAction action="#{cadastroFabricanteBean.inicializar}" />
</f:metadata>
<h1>Cadastro de Fabricante</h1>
<h:form id="frmCadastro">
<p:messages id="messages" autoUpdate="true" closable="true" />
<p:toolbar style="margin-top: 20px">
<p:toolbarGroup>
<p:commandButton value="Salvar"
action="#{cadastroFabricanteBean.salvar}" id="botaoSalvar" update="frmCadastro" />
</p:toolbarGroup>
<p:toolbarGroup align="right">
<p:button value="Pesquisa" outcome="pesquisaFabricante" />
</p:toolbarGroup>
</p:toolbar>
<p:panelGrid columns="2" id="painel"
style="width: 100%; margin-top: 20px" columnClasses="rotulo, campo">
<p:outputLabel value="Código" for="codigo" />
<p:inputText id="codigo"
value="#{cadastroFabricanteBean.fabricante.codigo}" size="20"
maxlength="20" readonly="true" />
<p:outputLabel value="Nome" for="nome" />
<p:inputText id="nome"
value="#{cadastroFabricanteBean.fabricante.nome}" size="60"
maxlength="80" />
</p:panelGrid>
</h:form>
</ui:define>
</ui:composition>
Meu Bean
package com.irmaosuspension.controleservico.controller;
import java.io.Serializable;
import javax.faces.view.ViewScoped;
import javax.inject.Inject;
import javax.inject.Named;
import org.omnifaces.util.Messages;
import com.irmaosuspension.controleservico.modelo.Fabricante;
import com.irmaosuspension.controleservico.service.FabricanteService;
import com.irmaosuspension.controleservico.util.NegocioException;
@Named
@ViewScoped
public class CadastroFabricanteBean implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
private FabricanteService cadastroFabricanteService;
private Fabricante fabricante;
public void inicializar() {
if (this.fabricante == null) {
limpar();
}
}
public void salvar()throws NegocioException {
try {
cadastroFabricanteService.salvar(fabricante);
Messages.addGlobalInfo("Fabricante salvo com sucesso!");
limpar();
} catch (NegocioException e) {
Messages.addGlobalError(e.getMessage());
}
}
public Fabricante getFabricante() {
return fabricante;
}
public void setFabricante(Fabricante fabricante) {
this.fabricante = fabricante;
}
public boolean isEditando() {
return this.fabricante.getCodigo() != null;
}
private void limpar() {
this.fabricante = new Fabricante();
}
}
Meu Service
package com.irmaosuspension.controleservico.service;
import java.io.Serializable;
import java.util.List;
import javax.inject.Inject;
import com.irmaosuspension.controleservico.dao.FabricanteDAO;
import com.irmaosuspension.controleservico.jpa.Transactional;
import com.irmaosuspension.controleservico.modelo.Fabricante;
import com.irmaosuspension.controleservico.util.NegocioException;
public class FabricanteService implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
private FabricanteDAO fabricanteDAO;
@Transactional
public void salvar(Fabricante fabricante) throws NegocioException {
if (fabricante.getNome().trim().equals("") || fabricante.getNome() == null) {
throw new NegocioException("O nome do fabricante é obrigatório");
}
this.fabricanteDAO.salvar(fabricante);
}
public List<Fabricante> buscarTodos() {
return fabricanteDAO.buscarTodos();
}
public void excluir(Fabricante fabricante) throws NegocioException {
try {
fabricanteDAO.excluir(fabricante);
} catch (Exception e) {
System.out.println(e.getMessage());
throw new NegocioException("Não foi possível excluir o Fabricante!");
}
}
}
Meu DAO
package com.irmaosuspension.controleservico.dao;
import java.io.Serializable;
import java.util.List;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceException;
import com.irmaosuspension.controleservico.jpa.Transactional;
import com.irmaosuspension.controleservico.modelo.Fabricante;
import com.irmaosuspension.controleservico.util.NegocioException;
public class FabricanteDAO implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
private EntityManager em;
public void salvar(Fabricante fabricante) {
em.merge(fabricante);
}
public List<Fabricante> buscarTodos() {
return em.createQuery("from Fabricante", Fabricante.class).getResultList();
}
@Transactional
public void excluir(Fabricante fabricante) throws NegocioException {
try {
Fabricante fabricanteTemp = this.buscarPeloCodigo(fabricante.getCodigo());
em.remove(fabricanteTemp);
em.flush();
} catch (PersistenceException e) {
throw new NegocioException("Fabricante não pode ser excluído.");
}
}
public Fabricante buscarPeloCodigo(Long codigo) {
return em.find(Fabricante.class, codigo);
}
}
Log ao tentar persistir:
mar 07, 2017 11:48:35 AM org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation
INFO: HHH000204: Processing PersistenceUnitInfo [
name: controleServico
...]
mar 07, 2017 11:48:35 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.1.0.Final}
mar 07, 2017 11:48:35 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
mar 07, 2017 11:48:35 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
mar 07, 2017 11:48:35 AM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
mar 07, 2017 11:48:36 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
mar 07, 2017 11:48:36 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/oficina]
mar 07, 2017 11:48:36 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {user=root, password=****}
mar 07, 2017 11:48:36 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
mar 07, 2017 11:48:36 AM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
Tue Mar 07 11:48:36 GMT-03:00 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
mar 07, 2017 11:48:36 AM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
OBS: Minha classe transação estão separadas, conseguindo persistir normal, só que agora não está mais.