每次在提交数据的时候,就提示错误,不知道是什么原因,请个位大哥大姐多多指教!!!T3.java
package com.mine.hiber;import java.io.Serializable;
import java.util.Set;/** @author Hibernate CodeGenerator */
public class T3 implements Serializable {    /** identifier field */
    private String username;    /** persistent field */
    private int id;    /** nullable persistent field */
    private String password;    /** nullable persistent field */
    private String address;    /** nullable persistent field */
    private String tel;    /** nullable persistent field */
    private String email;    /** nullable persistent field */
    private String sex;    /** nullable persistent field */
    private String enjoy;    /** nullable persistent field */
    private String content;    /** persistent field */
    private Set t1s;    /** persistent field */
    private Set t2s;    /** full constructor */
    public T3(String username, String password, String tel, String email, String sex, String enjoy, String content) {
        this.username = username;
        this.password = password;
        this.tel = tel;
        this.email = email;
        this.sex = sex;
        this.enjoy = enjoy;
        this.content = content;
    
    }    /** default constructor */
    public T3() {
    }    /** minimal constructor */
    public T3(String username, int id, Set t1s, Set t2s) {
        this.username = username;
        this.id = id;
        this.t1s = t1s;
        this.t2s = t2s;
    }    public String getUsername() {
        return this.username;
    }    public void setUsername(String username) {
        this.username = username;
    }    public int getId() {
        return this.id;
    }    public void setId(int id) {
        this.id = id;
    }    public String getPassword() {
        return this.password;
    }    public void setPassword(String password) {
        this.password = password;
    }    public String getAddress() {
        return this.address;
    }    public void setAddress(String address) {
        this.address = address;
    }    public String getTel() {
        return this.tel;
    }    public void setTel(String tel) {
        this.tel = tel;
    }    public String getEmail() {
        return this.email;
    }    public void setEmail(String email) {
        this.email = email;
    }    public String getSex() {
        return this.sex;
    }    public void setSex(String sex) {
        this.sex = sex;
    }    public String getEnjoy() {
        return this.enjoy;
    }    public void setEnjoy(String enjoy) {
        this.enjoy = enjoy;
    }    public String getContent() {
        return this.content;
    }    public void setContent(String content) {
        this.content = content;
    }    public Set getT1s() {
        return this.t1s;
    }    public void setT1s(Set t1s) {
        this.t1s = t1s;
    }    public Set getT2s() {
        return this.t2s;
    }    public void setT2s(Set t2s) {
        this.t2s = t2s;
    }}
RgeFrom.java/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.mine.struts.action;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.hibernate.Session;
import org.hibernate.Transaction;
//import org.apache.struts.action.ActionMessage;
//import org.apache.struts.action.ActionMessages;import com.mine.hiber.SessionFactory;
import com.mine.hiber.T3;
import com.mine.struts.form.RegForm;/** 
 * MyEclipse Struts
 * Creation date: 06-13-2008
 * 
 * XDoclet definition:
 * @struts.action path="/reg" name="regForm" input="/reg.jsp" scope="request" validate="true"
 */
public class RegAction extends Action {
/*
 * Generated Methods
 */ /** 
 * Method execute
 * @param mapping
 * @param form
 * @param request
 * @param response
 * @return ActionForward
 */
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) 
{
         RegForm regForm = (RegForm) form;// TODO Auto-generated method stub
//String username=regForm.getUsername();
// ActionMessages messages=new ActionMessages();
//ActionForward maps=null;
// String password=request.getParameter("password");
//if (username==null || "".equals(username))
//{

// ActionMessage usmsg=new ActionMessage("username.error",username);
// messages.add("username",usmsg);
// saveErrors(request,messages);
// if (password==null || "".equals(password))
// {
// ActionMessage psmsg=new ActionMessage("password.error",password);
  //      messages.add("password",psmsg);
  //      saveErrors(request,messages);
// }
// maps=mapping.getInputForward();
//}
// else
// {
// maps=mapping.findForward("success");
//}
         
         Session sessiont3=SessionFactory.getSession();
         Transaction tx=sessiont3.beginTransaction();
         String msg=null;
         String username=regForm.getUsername();
         String password=regForm.getPassword();
         String tel=regForm.getTel();
         String email=regForm.getEmail();
         String sex=regForm.getSex();
         
         String enjoy[];
         enjoy=regForm.getEnjoy();
         String ens="";
         for(int i=0;i<enjoy.length;i++)
         {
         ens=ens+enjoy[i]+",";
         }
         ens=ens.trim();
         
         String content=regForm.getZwjs();
         
         T3 users=new T3(username,password,tel,email,sex,ens,content);
       sessiont3.save(users);
         tx.commit();
         sessiont3.close();
         HttpSession session = request.getSession();  
      msg=username+"注册成功!";
         session.setAttribute("username", msg);
         
return mapping.findForward("success");
}
}

解决方案 »

  1.   

    T3.hbm.xml<?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
        
    <hibernate-mapping>
    <!-- 
        Created by the Middlegen Hibernate plugin 2.2    http://boss.bekk.no/boss/middlegen/
        http://www.hibernate.org/
    --><class 
        name="com.mine.hiber.T3" 
        table="T3"
        lazy="false"
    >    <id
            name="username"
            type="java.lang.String"
            column="username"
        >
        
            <generator class="assigned" />
        </id>    <property
            name="id"
            type="int"
            column="id"
            not-null="true"
            length="10"
        />
        <property
            name="password"
            type="java.lang.String"
            column="password"
            length="20"
        />
        <property
            name="address"
            type="java.lang.String"
            column="address"
            length="50"
        />
        <property
            name="tel"
            type="java.lang.String"
            column="tel"
            length="50"
        />
        <property
            name="email"
            type="java.lang.String"
            column="email"
            length="50"
        />
        <property
            name="sex"
            type="java.lang.String"
            column="sex"
            length="10"
        />
        <property
            name="enjoy"
            type="java.lang.String"
            column="enjoy"
            length="50"
        />
        <property
            name="content"
            type="java.lang.String"
            column="content"
            length="200"
        />    <!-- Associations -->
      
        <!-- bi-directional one-to-many association to T1 -->    <set
            name="t1s"
            lazy="true"
            inverse="true"
    cascade="all"    >
            <key>
                <column name="username1" />
            </key>
            
            <one-to-many 
                class="com.mine.hiber.T1"
            />
        </set>
        <!-- bi-directional one-to-many association to T2 -->    <set
            name="t2s"
            lazy="true"
            inverse="true"
    cascade="all"    >
            <key>
                <column name="username2" />
            </key>
            
            <one-to-many 
                class="com.mine.hiber.T2"
            />
        </set></class>
    </hibernate-mapping>
    错误提示
    exception javax.servlet.ServletException: Servlet execution threw an exception
    root cause java.lang.NoClassDefFoundError: org/hibernate/Session
    com.mine.struts.action.RegAction.execute(RegAction.java:71)
    org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
    org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
    org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      

  2.   

    hibernate包引入問題,不是說java.lang.NoClassDefFoundError: org/hibernate/Session 
    沒有找到org/hibernate/Session類嗎?
      

  3.   

    找session啦,在eclipse中没有任何的红叉号,而且我引用的也是org/hibernate/Session啊
      

  4.   

    楼主的校验可以在ActionFrom里面嘛,没必要写在ActionServlet里面啊
      

  5.   

    按错误信息来看没有找到Session类
    应该是包引入问题吧
      

  6.   

     刚才试了试,去掉这句之后就没有错误提示了,Transaction tx=sessiont3.beginTransaction();难道这句有问题吗?请个位帮忙解释一下!
      

  7.   

    Transaction tx=null;
    定义为全局静态变量
    然后里面tx=sessiont3.get
    试试看(@#*%(@#%(@#%(@%
    不要问我为什么。
      

  8.   

    楼主调用了hibernate的save()方法,所以必须要开启事务的,这一句Transaction tx=sessiont3.beginTransaction();是必须要的.
    再说,楼主那个RegAction类的execute方法写的太不规范了吧.
      

  9.   

    错误提示 是你的jar文件导入有问题 缺少类 你要是用eclipse的话 应该编译不通过的才对
      

  10.   

    eclipse没有提示任何错误,有错的话,我怎么去提交数据呢,让大家费心了!
      

  11.   

    hibernate包的版本不对,重新找个包导入就OK
      

  12.   

    是T3.hbm.xml这个配置文件的原因,我把下面的代码去掉之后就行了,我的这个表是个一对多的主表,但是
    为什么会这样,我知道在它提交数据的进行初始化,但是为什么会提示出那样的错误来呢,请各位指教!
     <set name="t2s" inverse="true">
                <key>
                    <column name="aa" length="10" not-null="true" />
                </key>
                <one-to-many class="com.mine.hiber.T2" />
            </set>
            <set name="t1s" inverse="true">
                <key>
                    <column name="ddd" length="10" not-null="true" />
                </key>
                <one-to-many class="com.mine.hiber.T1" />
            </set>