Bom dia galera do GUJ, estou com um problema… estou realizando um conexão com o Hibernate + Oracle … creio que a conexão está perfeita pois eu consigo acessar o banco via netbeans e criar tabelas no sql brutoo!
a minha class hibernate reponsavel por fazer a conexão com o banco é essa
factory = new AnnotationConfiguration()
.setProperty("hibernate.dialect", "org.hibernate.dialect.Oracle10gDialect")
.setProperty("hibernate.connection.driver_class", "oracle.jdbc.driver.OracleDriver")
.setProperty("hibernate.connection.url", "jdbc:oracle:thin:@10.14.6.8:1521:XE")
.setProperty("hibernate.connection.username", "devrpc")
.setProperty("hibernate.connection.password", "rpctv")
.setProperty("hibernate.hbm2ddl.auto", "update")
.setProperty("hibernate.c3p0.max_size", "10")
.setProperty("hibernate.c3p0.min_size", "2")
.setProperty("hibernate.c3p0.timeout", "5000")
.setProperty("hibernate.c3p0.max_statements", "10")
.setProperty("hibernate.c3p0.idle_test_period", "3000")
.setProperty("hibernate.c3p0.acquire_increment", "2")
.setProperty("show_sql", "true")
.setProperty("use_outer_join", "true")
.setProperty("hibernate.generate_statistics", "true")
.setProperty("hibernate.use_sql_comments", "true")
.setProperty("hibernate.format_sql", "true")
.addAnnotatedClass(Aluno.class)
o meu erro que está acontecendo é no console do GlassFish 3.1 o tal erro é este
INFO: Grizzly Framework 1.9.31 started in: 0ms - bound to [0.0.0.0:8484]
INFO: WEB0169: Created HTTP listener [http-listener-2] on host/port [0.0.0.0:8181]
INFO: Grizzly Framework 1.9.31 started in: 0ms - bound to [0.0.0.0:8181]
INFO: JSF1027: [null] Os ELResolvers para JSF não foram registrados com o contêiner JSP.
GRAVE: Class [ dao/DaoGenerico ] not found. Error while loading [ class controle.ControleAluno ]
GRAVE: Class [ dao/DaoGenerico ] not found. Error while loading [ class controle.ControleAluno ]
INFO: Inicializando Mojarra 2.1.0 (FCS 2.1.0-b11) para o contexto '/DEVRPC'
INFO: WEB0671: Loading application [DEVRPC] at [/DEVRPC]
INFO: DEVRPC foi implementado com êxito em 7.250 milisegundos.
A class ControleAluno é esta:
package controle;
import dao.DaoGenerico;
import dao.DaoHibernateGenerico;
import entidade.Aluno;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* @author jaime
*/
@WebServlet(name = "ControleAluno.jsp", urlPatterns = {"ControleAluno"})
public class ControleAluno extends HttpServlet {
DaoGenerico dao = new DaoHibernateGenerico();
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Aluno alu = new Aluno();
String acao = request.getParameter("acao");
if (acao.equals("salvar")) {
alu.setRa(request.getParameter("ra"));
alu.setNome(request.getParameter("nome"));
dao.save(alu);
} else if (acao.equals("excluir")) {
alu = (Aluno) dao.getById(Long.parseLong(request.getParameter("id")), Aluno.class);
dao.delete(alu);
}
List<Aluno> lista = new ArrayList<Aluno>();
lista = dao.list(Aluno.class);
request.setAttribute("listaAlunos", lista);
request.getRequestDispatcher("index.jsp").forward(request, response);
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Returns a short description of the servlet.
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}
DaoGenerico
package dao;
import java.io.Serializable;
import java.util.List;
public interface DaoGenerico {
public Object save(Object objeto);
public void delete(Object objeto);
public List list(Class clazz);
public List listCriterio(Class clazz, String atributo, String criterio);
public Object getById(Serializable id, Class clazz);
}
e o meu DaoHibernateGenerico
mport util.HibernateUtil;
import java.io.Serializable;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
public class DaoHibernateGenerico implements DaoGenerico {
@Override
public Object save(Object objeto) {
try {
Object obj = null;
HibernateUtil.beginTransaction();
obj = HibernateUtil.getSession().merge(objeto);
HibernateUtil.commitTransaction();
HibernateUtil.closeSession();
return obj;
} catch (HibernateException hibernateException) {
HibernateUtil.rollbackTransaction();
HibernateUtil.closeSession();
throw hibernateException;
}
}
@Override
public void delete(Object objeto) {
try {
HibernateUtil.beginTransaction();
HibernateUtil.getSession().delete(objeto);
HibernateUtil.commitTransaction();
HibernateUtil.closeSession();
} catch (HibernateException hibernateException) {
HibernateUtil.rollbackTransaction();
throw new RuntimeException(hibernateException);
}
}
public List list(Class clazz) {
try {
List lista = null;
lista = HibernateUtil.getSession().createCriteria(clazz).list();
return lista;
} catch (HibernateException hibernateException) {
HibernateUtil.rollbackTransaction();
throw new RuntimeException(hibernateException);
}
}
public Object getById(Serializable id, Class clazz) {
try {
Object obj = HibernateUtil.getSession().get(clazz, id);
return obj;
} catch (HibernateException hibernateException) {
HibernateUtil.rollbackTransaction();
throw new RuntimeException(hibernateException);
}
}
public List listCriterio(Class clazz, String atributo, String criterio) {
try {
List lista = null;
Criteria crit = HibernateUtil.getSession().createCriteria(clazz, atributo);
crit.add(Restrictions.ilike(atributo, "%" + criterio + "%"));
crit.addOrder(Order.asc(atributo));
crit.setMaxResults(30);
lista = crit.list();
HibernateUtil.closeSession();
return lista;
} catch (HibernateException hibernateException) {
HibernateUtil.rollbackTransaction();
throw new RuntimeException(hibernateException);
}
}
}
Bom na minha View eu passo pro meu controle aluno atravez de uma action a variavel ControleAluno
eu creio que o erro deva ser com o servlets porque parece que os parametros não são passados para o meu controlealuno para então ser persistida no banco!!! como o erro diz… é impossivel carregar a class dao/daogenerico
alguem pode me ajudar? Grato!