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
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.
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() {
}
}
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee">
<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>
</web-app>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Cadastro de usuarios</title>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
</head>
<body>
<h1>Cadastro de usuarios</h1>
<form action="usuario.adiciona.logic">
Login: <input type="text" name="usuario.login" /><br/>
Senha: <input type="text" name="usuario.senha" /><br/>
<input type="submit" />
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Usuario adicionado com sucesso</title>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
</head>
<body>
<h2>Usuario ${param['usuario.login']} adicionado com sucesso!</h2>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="hibernate.connection.url">
jdbc:mysql://localhost/test
</property>
<property name="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">xxxx</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<mapping class="br.com.caelum.lojavirtual.modelo.Usuario"/>
</session-factory>
</hibernate-configuration>