Oi gente, estou fazendo os exercícios da apostila FJ28 da caelum e estou com o seguinte erro no exercício 5.3 que adiciona login e senha no MySQL.
A lógica do hibernate está funcionando, pois consigo inserir e consultar com a classe de teste. Enviarei alguns códigos abaixo pra alguém analisar, por favor.
Obrigado.
O erro
[b]HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: org/hibernate/cfg/Configuration
org.vraptor.VRaptorServlet.service(VRaptorServlet.java:95)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
br.com.caelum.lojavirtual.logic.UsuarioLogic.adiciona(UsuarioLogic.java:16)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.vraptor.component.DefaultLogicMethod.execute(DefaultLogicMethod.java:61)
org.vraptor.interceptor.ExecuteLogicInterceptor.intercept(ExecuteLogicInterceptor.java:32)
org.vraptor.core.InterceptorsLogicFlow.execute(InterceptorsLogicFlow.java:72)
org.vraptor.interceptor.SettingAndValidationInterceptor.intercept(SettingAndValidationInterceptor.java:131)
org.vraptor.core.InterceptorsLogicFlow.execute(InterceptorsLogicFlow.java:72)
org.vraptor.interceptor.InjectionInterceptor.intercept(InjectionInterceptor.java:41)
org.vraptor.core.InterceptorsLogicFlow.execute(InterceptorsLogicFlow.java:72)
org.vraptor.interceptor.ComponentLookupInterceptor.intercept(ComponentLookupInterceptor.java:58)
org.vraptor.core.InterceptorsLogicFlow.execute(InterceptorsLogicFlow.java:72)
org.vraptor.interceptor.FlashScopeInterceptor.intercept(FlashScopeInterceptor.java:22)
org.vraptor.core.InterceptorsLogicFlow.execute(InterceptorsLogicFlow.java:72)
org.vraptor.interceptor.RegisterAttributesInteceptor.intercept(RegisterAttributesInteceptor.java:38)
org.vraptor.core.InterceptorsLogicFlow.execute(InterceptorsLogicFlow.java:72)
org.vraptor.core.VRaptorExecution.execute(VRaptorExecution.java:98)
org.vraptor.core.DefaultController.execute(DefaultController.java:46)
org.vraptor.VRaptorServlet.service(VRaptorServlet.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.16 logs.[/b]
[code]
package br.com.caelum.lojavirtual.logic;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.vraptor.annotations.Component;
import br.com.caelum.lojavirtual.dao.Dao;
import br.com.caelum.lojavirtual.modelo.Usuario;
import br.com.caelum.lojavirtual.util.HibernateUtil;
@Component
public class UsuarioLogic {
public void adiciona (Usuario usuario) {
// configura o hibernate
Session session = HibernateUtil.getSession();
Dao<Usuario> dao = new Dao<Usuario>(session,Usuario.class);
Transaction t = session.beginTransaction();
dao.adiciona(usuario);
t.commit();
System.out.println("Adiciona usuario " + usuario.getLogin());
}
public void formulario() {
}
}[/code]
web.xml
[code]<?xml version="1.0" encoding="ISO-8859-1"?>
<servlet>
<servlet-name>vraptor2</servlet-name>
<servlet-class>org.vraptor.VRaptorServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>vraptor2</servlet-name>
<url-pattern>*.logic</url-pattern>
</servlet-mapping>
[/code]
A tela com os campos de inserir login e senha
[code]<%@ page language=“java” contentType=“text/html; charset=ISO-8859-1”
pageEncoding=“ISO-8859-1”%>
Cadastro de usuarios
Login:Senha:
</body>
[/code]
A tela que mostra que houve sucesso na inserção
[code]<%@ page language=“java” contentType=“text/html; charset=ISO-8859-1”
pageEncoding=“ISO-8859-1”%>
Usuario ${param['usuario.login']} adicionado com sucesso!
[/code][code]<?xml version="1.0" encoding="UTF-8"?>
com.mysql.jdbc.Driver jdbc:mysql://localhost/test org.hibernate.dialect.MySQLDialect root xxxx true true [/code]