Exception ao criar classe DAO

3 respostas
Solfier

Sou iniciante em java e para aprender resolvi fazer um sistema de cadastro com struts e hibernate. Porém, ao criar a classe DAO, é gerada uma excessao.

onde que estou errando?

ai vão as classes:

JSP:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<!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=UTF-8">
        <title>JPLincensing</title>
    </head>
    <body>
        <html:form action="/addLicenca">
            <table border="1">
                    <tr>
                        <td align="center" colspan="2" valign="top">
                            <h3>Computador</h3>
                            <html:select name="licencaForm" property="computadorCodigo" multiple="true" size="10" style="width:200px">
                                <html:optionsCollection property="computadores" value="computadorId" label="codigo"/>
                            </html:select>
                        </td>
                    </tr>
                    <tr>
                        <td><html:submit value="Inserir"/></td>
                    </tr>
            </table>
        </html:form>
    </body>
</html>
VO:
package br.jpjornal.licensing.vo;
// Generated 22/03/2010 13:01:31 by Hibernate Tools 3.2.1.GA

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

public class Computador implements java.io.Serializable {

    private Integer computadorId;
    private Setor setor;
    private String codigo;
    private String marca;
    private String modelo;
    private Date arquisicao;
    private Date garantia;
    private String processador;
    private String frequencia;
    private String memoria;
    private String hd;
    private String driver;
    private String driverTipo;
    private Set usuarios = new HashSet(0);
    private Set licencas = new HashSet(0);

    public Computador() {
    }

    public Computador(Setor setor, String codigo, String marca, String modelo, Date arquisicao, Date garantia, String processador, String frequencia, String memoria, String hd, String driver, String driverTipo, Set usuarios, Set licencas) {
        this.setor = setor;
        this.codigo = codigo;
        this.marca = marca;
        this.modelo = modelo;
        this.arquisicao = arquisicao;
        this.garantia = garantia;
        this.processador = processador;
        this.frequencia = frequencia;
        this.memoria = memoria;
        this.hd = hd;
        this.driver = driver;
        this.driverTipo = driverTipo;
        this.usuarios = usuarios;
        this.licencas = licencas;
    }

    public Integer getComputadorId() {
        return this.computadorId;
    }

    public void setComputadorId(Integer computadorId) {
        this.computadorId = computadorId;
    }

    public Setor getSetor() {
        return this.setor;
    }

    public void setSetor(Setor setor) {
        this.setor = setor;
    }

    public String getCodigo() {
        return this.codigo;
    }

    public void setCodigo(String codigo) {
        this.codigo = codigo;
    }

    public String getMarca() {
        return this.marca;
    }

    public void setMarca(String marca) {
        this.marca = marca;
    }

    public String getModelo() {
        return this.modelo;
    }

    public void setModelo(String modelo) {
        this.modelo = modelo;
    }

    public Date getArquisicao() {
        return this.arquisicao;
    }

    public void setArquisicao(Date arquisicao) {
        this.arquisicao = arquisicao;
    }

    public Date getGarantia() {
        return this.garantia;
    }

    public void setGarantia(Date garantia) {
        this.garantia = garantia;
    }

    public String getProcessador() {
        return this.processador;
    }

    public void setProcessador(String processador) {
        this.processador = processador;
    }

    public String getFrequencia() {
        return this.frequencia;
    }

    public void setFrequencia(String frequencia) {
        this.frequencia = frequencia;
    }

    public String getMemoria() {
        return this.memoria;
    }

    public void setMemoria(String memoria) {
        this.memoria = memoria;
    }

    public String getHd() {
        return this.hd;
    }

    public void setHd(String hd) {
        this.hd = hd;
    }

    public String getDriver() {
        return this.driver;
    }

    public void setDriver(String driver) {
        this.driver = driver;
    }

    public String getDriverTipo() {
        return this.driverTipo;
    }

    public void setDriverTipo(String driverTipo) {
        this.driverTipo = driverTipo;
    }

    public Set getUsuarios() {
        return this.usuarios;
    }

    public void setUsuarios(Set usuarios) {
        this.usuarios = usuarios;
    }

    public Set getLicencas() {
        return this.licencas;
    }

    public void setLicencas(Set licencas) {
        this.licencas = licencas;
    }
}
DAO:
package br.jpjornal.licensing.dao;

import java.util.Collection;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import br.jpjornal.licensing.hibernate.HibernateUtil;
import br.jpjornal.licensing.vo.Computador;

public class ComputadorDAO {

    private SessionFactory factory;
    private Session session;

    public ComputadorDAO() throws Exception {
        this.factory = HibernateUtil.getSessionFactory();
        this.session = factory.openSession();
    }

    public void insert(Computador computador) throws Exception {
        Transaction transaction = session.beginTransaction();
        session.save(computador);
        transaction.commit();
    }

    public void delete(Computador computador) throws Exception {
        Transaction transaction = session.beginTransaction();
        session.delete(computador);
        transaction.commit();
    }

    public void update(Computador computador) throws Exception {
        Transaction transaction = session.beginTransaction();
        session.update(computador);
        transaction.commit();
    }

    public Collection list(String condicao) throws Exception {
        Collection<Computador> computadores = null;
        computadores = session.createQuery(condicao).list();
        return computadores;
    }

    public Collection getCollection(String condicao) throws Exception {
        Collection computadores = session.createQuery(condicao).list();
        return computadores;
    }

    @Override
    protected void finalize() throws Throwable {
        super.finalize();
        session.flush();
        session.close();
    }
}
hbn:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 22/03/2010 13:01:41 by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
  <class catalog="licencas" name="br.jpjornal.licensing.hibernate.hbm.Computador" table="computador">
    <id name="computadorId" type="java.lang.Integer">
      <column name="computadorId"/>
      <generator class="identity"/>
    </id>
    <many-to-one class="br.jpjornal.licensing.hibernate.hbm.Setor" fetch="select" name="setor">
      <column name="setorId"/>
    </many-to-one>
    <property name="codigo" type="string">
      <column length="8" name="codigo"/>
    </property>
    <property name="marca" type="string">
      <column length="30" name="marca"/>
    </property>
    <property name="modelo" type="string">
      <column length="20" name="modelo"/>
    </property>
    <property name="arquisicao" type="date">
      <column length="10" name="arquisicao"/>
    </property>
    <property name="garantia" type="date">
      <column length="10" name="garantia"/>
    </property>
    <property name="processador" type="string">
      <column length="20" name="processador"/>
    </property>
    <property name="frequencia" type="string">
      <column length="10" name="frequencia"/>
    </property>
    <property name="memoria" type="string">
      <column length="10" name="memoria"/>
    </property>
    <property name="hd" type="string">
      <column length="15" name="hd"/>
    </property>
    <property name="driver" type="string">
      <column length="15" name="driver"/>
    </property>
    <property name="driverTipo" type="string">
      <column length="5" name="driverTipo"/>
    </property>
    <set inverse="false" name="usuarios" table="computadorUsuario">
      <key>
        <column name="computadorId" not-null="true"/>
      </key>
      <many-to-many entity-name="br.jpjornal.licensing.hibernate.hbm.Usuario">
        <column name="usuarioId" not-null="true"/>
      </many-to-many>
    </set>
    <set inverse="false" name="licencas" table="computadorLicenca">
      <key>
        <column name="computadorId" not-null="true"/>
      </key>
      <many-to-many entity-name="br.jpjornal.licensing.hibernate.hbm.Licenca">
        <column name="licencaId" not-null="true"/>
      </many-to-many>
    </set>
  </class>
</hibernate-mapping>

3 Respostas

jvictorcf

Você poderia postar a exception que esta sendo lançada?

jyoshiriro
  1. Qual o erro que dá? Você não o citou em seu post.

  2. Já que está iniciando, surge a pergunta: Por que Struts 1.x? Sugiro fortemente que estude Struts 2.x ou JSF ou SEAM. Struts 1.x está depreciado, ultrapassado, etc etc. O único bom motivo de estudar essa versão do Struts é se tiver com emprego em vista para cuidar de um sistema legado feito com ele.

Solfier
jvictorcf:
Você poderia postar a exception que esta sendo lançada?

Desculpa-me a falha:

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: javax.servlet.jsp.JspException: Exception thrown by getter for property computadores of bean org.apache.struts.taglib.html.BEAN
	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)

root cause

javax.servlet.ServletException: javax.servlet.jsp.JspException: Exception thrown by getter for property computadores of bean org.apache.struts.taglib.html.BEAN
	org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862)
	org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
	org.apache.jsp.licenca_jsp._jspService(licenca_jsp.java:92)
	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)

root cause

javax.servlet.jsp.JspException: Exception thrown by getter for property computadores of bean org.apache.struts.taglib.html.BEAN
	org.apache.struts.taglib.TagUtils.lookup(TagUtils.java:897)
	org.apache.struts.taglib.html.OptionsCollectionTag.doStartTag(OptionsCollectionTag.java:177)
	org.apache.jsp.licenca_jsp._jspx_meth_html_005foptionsCollection_005f0(licenca_jsp.java:213)
	org.apache.jsp.licenca_jsp._jspx_meth_html_005fselect_005f0(licenca_jsp.java:179)
	org.apache.jsp.licenca_jsp._jspx_meth_html_005fform_005f0(licenca_jsp.java:118)
	org.apache.jsp.licenca_jsp._jspService(licenca_jsp.java:82)
	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)
Criado 31 de março de 2010
Ultima resposta 31 de mar. de 2010
Respostas 3
Participantes 3