Hibernate Nullpointerexception

1. Hibernate Nullpointerexception

Carlos Fagiani Junior
terabytes

(usa Slackware)

Enviado em 01/01/2014 - 23:56h

Criei um Projeto EJB, e uma classe... Na hora do deploy me mostra esse erro logo abaixo. Está faltando importar algum jar? os que eu tenho são esses: antlr, dom4j, hibernate-commons-annotations, hibernate-core, hibernate-entitymanager, hibernate-jpa, jandex, javassist, jboss-logging, jboss-loging-annotations, jboss-transaction-api e estão dentro do 'EarContent/lib'.

Estou usando o glassfish, ele cria as tabelas no mysql corretamente, mas depois me retorna nulo.


2013-12-30T15:42:24.424-0300|INFO: visiting unvisited references
2013-12-30T15:42:29.030-0300|INFO: visiting unvisited references
2013-12-30T15:42:29.837-0300|INFO: visiting unvisited references
2013-12-30T15:42:29.848-0300|INFO: visiting unvisited references
2013-12-30T15:42:29.850-0300|INFO: visiting unvisited references
2013-12-30T15:42:30.284-0300|WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
2013-12-30T15:42:30.352-0300|INFO: HHH000204: Processing PersistenceUnitInfo [
name: conta
...]
2013-12-30T15:42:31.108-0300|INFO: HHH000412: Hibernate Core {4.3.0.Final}
2013-12-30T15:42:31.124-0300|INFO: HHH000206: hibernate.properties not found
2013-12-30T15:42:31.131-0300|INFO: HHH000021: Bytecode provider name : javassist
2013-12-30T15:42:32.280-0300|INFO: HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
2013-12-30T15:42:32.502-0300|INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
2013-12-30T15:42:43.453-0300|INFO: HHH000397: Using ASTQueryTranslatorFactory
2013-12-30T15:42:44.653-0300|INFO: HHH000228: Running hbm2ddl schema update
2013-12-30T15:42:44.655-0300|INFO: HHH000102: Fetching database metadata
2013-12-30T15:42:44.662-0300|INFO: HHH000396: Updating schema
2013-12-30T15:42:44.778-0300|INFO: HHH000261: Table found: kontak.Usuarios
2013-12-30T15:42:44.779-0300|INFO: HHH000037: Columns: [id_usuario, login, senha]
2013-12-30T15:42:44.780-0300|INFO: HHH000108: Foreign keys: []
2013-12-30T15:42:44.781-0300|INFO: HHH000126: Indexes: [uk_7ab8hfr59tske4yfe3c1r53xh, primary, uk_bww0gurxidq3j360jdhanymf6]
2013-12-30T15:42:44.784-0300|INFO: HHH000232: Schema update complete
2013-12-30T15:42:45.163-0300|WARNING: Exception while dispatching an event
java.lang.NullPointerException
at org.hibernate.engine.transaction.internal.jta.JtaStatusHelper.getStatus(JtaStatusHelper.java:76)
at org.hibernate.engine.transaction.internal.jta.JtaStatusHelper.isActive(JtaStatusHelper.java:118)
at org.hibernate.engine.transaction.internal.jta.CMTTransaction.join(CMTTransaction.java:149)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.joinTransaction(AbstractEntityManagerImpl.java:1602)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.postInit(AbstractEntityManagerImpl.java:210)
at org.hibernate.jpa.internal.EntityManagerImpl.<init>(EntityManagerImpl.java:91)
at org.hibernate.jpa.internal.EntityManagerFactoryImpl.internalCreateEntityManager(EntityManagerFactoryImpl.java:345)
at org.hibernate.jpa.internal.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:313)
at org.glassfish.persistence.jpa.JPADeployer$2.visitPUD(JPADeployer.java:451)
at org.glassfish.persistence.jpa.JPADeployer$PersistenceUnitDescriptorIterator.iteratePUDs(JPADeployer.java:510)
at org.glassfish.persistence.jpa.JPADeployer.iterateInitializedPUsAtApplicationPrepare(JPADeployer.java:492)
at org.glassfish.persistence.jpa.JPADeployer.event(JPADeployer.java:395)
at org.glassfish.kernel.event.EventsImpl.send(EventsImpl.java:131)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:484)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:219)
at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:491)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:527)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:523)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:356)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:522)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:546)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1423)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1500(CommandRunnerImpl.java:108)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1762)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1674)
at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:534)
at com.sun.enterprise.v3.admin.AdminAdapter.onMissingResource(AdminAdapter.java:224)
at org.glassfish.grizzly.http.server.StaticHttpHandler.service(StaticHttpHandler.java:297)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:246)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
at java.lang.Thread.run(Thread.java:724)

2013-12-30T15:42:45.229-0300|INFO: EJB5181:Portable JNDI names for EJB UsuarioSessionBean: [java:global/kontakEAR/kontak/UsuarioSessionBean, java:global/kontakEAR/kontak/UsuarioSessionBean!br.com.kontak.contratoEjb.UsuarioRemote]
2013-12-30T15:42:45.230-0300|INFO: EJB5182:Glassfish-specific (Non-portable) JNDI names for EJB UsuarioSessionBean: [br.com.kontak.contratoEjb.UsuarioRemote#br.com.kontak.contratoEjb.UsuarioRemote, br.com.kontak.contratoEjb.UsuarioRemote]
2013-12-30T15:42:49.026-0300|INFO: Inicializando Mojarra 2.2.0 ( 20130502-2118 https://svn.java.net/svn/mojarra~svn/tags/2.2.0@11930) para o contexto '/kontakWEB'
2013-12-30T15:42:50.574-0300|INFO: Running on PrimeFaces 4.0
2013-12-30T15:42:50.597-0300|INFO: Loading application [kontakEAR#kontakWEB.war] at [kontakWEB]
2013-12-30T15:42:50.674-0300|INFO: kontakEAR foi implantado com sucesso em 37.361 milissegundos.


Esse é o persistence.xml


<?xml version="1.0" encoding="UTF-8"?>
<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="kontak" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>

<!-- Informações do dataSource -->
<jta-data-source>jdbc/kontak</jta-data-source>

<!-- Informações das entidades -->
<class>br.com.kontak.entidade.Usuarios</class>
<!-- <class>br.com.kontak.entidade.Telefones</class> -->

<properties>
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
</properties>
</persistence-unit>
</persistence>



Aqui a Entity Usuarios.java


package br.com.kontak.entidade;

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.Table;

@Entity
@Table(name="Usuarios")
public class Usuarios implements Serializable {
private static final long serialVersionUID = -9076390670243433730L;

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="id_usuario", unique=true, nullable=false)
private Integer idUsuario;

@Column(name="login", unique=true, nullable=false, length=20)
private String login;

@Column(name="senha", unique=true, nullable=false, length=32)
private String senha;

public Integer getIdUsuario() {
return idUsuario;
}

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;
}
}


aqui o UsuarioRemote.java

package br.com.kontak.contratoEjb;

import java.util.List;
import javax.ejb.Remote;
import br.com.kontak.entidade.Usuarios;

@Remote
public interface UsuarioRemote {

void salvar(Usuarios usuario);
List<Usuarios> listarUsuarios();
void excluir(Usuarios usuario);
}


aqui o UsuarioSessionbean.java


package br.com.kontak.sessionBean;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

import br.com.kontak.contratoEjb.UsuarioRemote;
import br.com.kontak.entidade.Usuarios;

@Stateless
public class UsuarioSessionBean implements UsuarioRemote {
@PersistenceContext
private EntityManager entity;

@Override
public void salvar(Usuarios usuario) {
entity.persist(usuario);
}

@Override
public List<Usuarios> listarUsuarios() {
TypedQuery<Usuarios> query = entity.createQuery(
"select c1 from Usuarios c1", Usuarios.class);
return query.getResultList();
}

@Override
public void excluir(Usuarios usuario) {
usuario = entity.find(Usuarios.class, usuario.getIdUsuario());
entity.remove(usuario);
}
}


Aqui o Usuariobean.java que está na parte WEB


package br.com.kontak.managedBean;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.ManagedBean;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.faces.application.FacesMessage;
import javax.faces.application.FacesMessage.Severity;
import javax.faces.context.FacesContext;

import br.com.kontak.contratoEjb.UsuarioRemote;
import br.com.kontak.entidade.Usuarios;

@ManagedBean
@RequestScoped
public class UsuarioBean {
@EJB
private UsuarioRemote usuarioRemote;

private Usuarios usuario;

private List listaUsuarios;

public void salvar() {

try {
//criar md5 senha
usuario.setLogin(usuario.getLogin());
usuario.setSenha(usuario.getSenha());
this.usuarioRemote.salvar(usuario);
retornar();
} catch (Exception e) {
this.addMensagem(FacesMessage.SEVERITY_WARN, "Erro ao salvar");
}
}

private void retornar() {
this.addMensagem(FacesMessage.SEVERITY_INFO, "Operação realizada com sucesso");
this.listarUsuarios();
usuario = new Usuarios();
}

public void excluir() {
this.usuarioRemote.excluir(getUsuario());
usuario = new Usuarios();
this.listarUsuarios();
}

private void addMensagem(Severity tipo, String msg) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(tipo,"",msg));
}

public void listarUsuarios() {
this.listaUsuarios = this.usuarioRemote.listarUsuarios();
}

public void limpar() {
usuario = new Usuarios();
listaUsuarios = new ArrayList();
}

public Usuarios getUsuario() {
if (usuario == null) {
usuario = new Usuarios();
}
return usuario;
}

public void setUsuario(Usuarios usuario) {
this.usuario = usuario;
}

public List getListaUsuarios() {
if (listaUsuarios == null) {
this.listarUsuarios();
}
return listaUsuarios;
}

public void setListaUsuarios(List listaUsuarios) {
this.listaUsuarios = listaUsuarios;
}
}



alguem sabe onde eu errei, ou o que estou esquecendo de colocar... obrigado


  






Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts