Olá amigos,
Meu nome é Anderson Martins, e estou querendo fazer um sisteminha pra treinar Java e aprender mais coisas, como por ex:. frameworks Hibernate, Struts e Spring.
O que to montando me baseando em alguns exercícios e exemplos de sala de aula, é um sistema para Bolão seja ele de qualquer campeonato, onde o administrador poderá cadastrar os apostadores, os jogos e as apostas dos apostadores, saindo depois um relatório pelo IReport de classificação e comparação dos resultados oficiais e as apostas dos jogadores, e assim atribuidos seus devidos pontos.
me encontro numa situação de erro de conexão com MySql eu acho, mas não sei qual o erro certo gostaria de uma ajuda.
colocarei aqui os códigos que criei, e por último o erro, se puder me ajudar ficaria muito grato e no que eu puder ajudar, pode pedir.
CadastroAposta.jsp
[code]<%@page contentType=“text/html” pageEncoding=“UTF-8”%>
<jsp:useBean id=“objAposta” class=“Entidades.Aposta” scope=“page” />
<jsp:useBean id=“objDAO” class=“DAO.ApostaDAO” scope=“page” />
<jsp:setProperty name=“objAposta” property="*" />
<%
//Unidade de trabalho (INSERE)
objDAO.beginHibernate();
objDAO.insertAposta(objAposta);
objDAO.commitTransaction();
objDAO.closeSession();
%>
|
Aposta.java
[code]
package Entidades;
import java.io.Serializable;
import javax.persistence.*;
@Entity
@Table(name=“aposta”)
public class Aposta implements Serializable{
@Id
@GeneratedValue
@Column(name=“idaposta”)
private int aposta;
@Column(name=“goltime1”)
private int gl1;
@Column(name=“goltime2”)
private int gl2;
public int getGl1() { return gl1;}
public int getAposta() { return aposta; }
public int getGl2() { return gl2; }
public void setAposta(int aposta) { this.aposta = aposta; }
public void setGl1(int gl1) { this.gl1 = gl1; }
public void setGl2(int gl2) { this.gl2 = gl2; }
}[/code]
ApostaDAO.java
[code]
package DAO;
import Entidades.Aposta;
import org.hibernate.*;
import java.util.List;
public class ApostaDAO {
private Session session = null;
private Transaction transaction = null;
public void insertAposta(Aposta obj) {
Integer id = (Integer)session.save(obj);
obj.setAposta(id); //o Id de Aposta é matr
}
public void updateAposta(Aposta obj) {
session.update(obj);
}
public void deleteAposta(Aposta obj) {
session.delete(obj);
}
public Aposta loadAposta(int matr) {
Aposta obj = (Aposta) session.load(Aposta.class, matr);
return obj;
}
@SuppressWarnings(“unchecked”) //warning query.list()
public List listAllApostas() {
Query query = session.createQuery(“from Aposta”);
List Apostas = query.list();
return Apostas;
}
@SuppressWarnings(“unchecked”) //warning query.list()
public List buscaApostas(String n) {
Query query = session.createQuery(“from Aposta as p " +
“where p.nome like '%”+n+”%’");
List Apostas = query.list();
return Apostas;
}
//////////////////////////////////////////////////////////////////
//begin
public void beginHibernate() {
try
{ session = HibernateUtil.getSession();
transaction = session.beginTransaction();
} catch (HibernateException e) {
System.out.println("\nErro Begin Hibernate.\n\n");
e.printStackTrace();
}
}
//commit
public void commitTransaction() {
try {
transaction.commit();
} catch (HibernateException e) {
System.out.println("\nError Commit Transaction.\n\n");
e.printStackTrace();
}
}
//close
public void closeSession() {
try {
session.close();
} catch (HibernateException e) {
System.out.println("\nError Close Session.\n\n");
e.printStackTrace();
}
}
}[/code]
HibernateUtil.java
package DAO;
import org.hibernate.*;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.SessionFactory;
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
// Create the SessionFactory from standard (hibernate.cfg.xml)
// config file.
sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
} catch (Throwable ex) {
// Log the exception.
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
public static Session getSession(){
return getSessionFactory().openSession();
}
}
hibernate.cfg.xml
<?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.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/bd_bolao2010</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<mapping resource="DAO/hibernate.hbm.xml"/>
<mapping resource="DAO/hibernate.hbm.xml"/>
<mapping resource="DAO/hibernate.hbm.xml"/>
<mapping resource="DAO/hibernate.hbm.xml"/>
<mapping resource="Entidades/hibernate.hbm.xml"/>
<mapping resource="Entidades/hibernate.hbm.xml"/>
<mapping resource="DAO/hibernate.hbm.xml"/>
</session-factory>
</hibernate-configuration>
ERRO
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.ExceptionInInitializerError
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:522)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:398)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
root cause
javax.servlet.ServletException: java.lang.ExceptionInInitializerError
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
org.apache.jsp.CadastroAposta_jsp._jspService(CadastroAposta_jsp.java:145)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
root cause
java.lang.ExceptionInInitializerError
DAO.HibernateUtil.(HibernateUtil.java:28)
DAO.ApostaDAO.beginHibernate(ApostaDAO.java:48)
org.apache.jsp.CadastroAposta_jsp._jspService(CadastroAposta_jsp.java:83)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
root cause
org.hibernate.HibernateException: /hibernate.cfg.xml not found
org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:147)
org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1405)
org.hibernate.cfg.Configuration.configure(Configuration.java:1427)
org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:972)
org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:69)
org.hibernate.cfg.Configuration.configure(Configuration.java:1414)
org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:966)
DAO.HibernateUtil.(HibernateUtil.java:24)
DAO.ApostaDAO.beginHibernate(ApostaDAO.java:48)
org.apache.jsp.CadastroAposta_jsp._jspService(CadastroAposta_jsp.java:83)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.20 logs.
Apache Tomcat/6.0.20[/code]