您的位置:程序门 -> java -> 框架、开源



struts+hibernate的一个问题,一直解决不了,请高手帮忙


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


struts+hibernate的一个问题,一直解决不了,请高手帮忙
发表于:2008-01-16 16:02:45 楼主
该错误主要是在执行插入操作时候报的错

错误:
15:12:17,312   debug   essuserdaohibernate:47   -   net.sf.hibernate.jdbcexception:   could   not   load:   [com.sunyard.approve.bean.essuser#sdfas@163.com]
15:15:25,000   debug   essuserdaohibernate:84   -   net.sf.hibernate.jdbcexception:   could   not   insert:   [com.sunyard.approve.bean.essuser#sdfas@163.com]

essuser就是一个javabean,里面就只有get和set方法。


用户处理从视图层传过来的action中增加用户的方法为:
      public   actionforward   adduser(actionmapping   actionmapping,   actionform   actionform,   httpservletrequest   httpservletrequest,   httpservletresponse   httpservletresponse)   {
        /**@todo:   complete   the   business   logic   here,   this   is   just   a   skeleton.*/
        reguserform   loginform   =   (reguserform)   actionform;
        essuser   essuser=new   essuser();
        string   target="addok";
        httpservletrequest.removeattribute("error");
        essuserdaohibernate   userdao=new   essuserdaohibernate();
        try{          
          essuser=(essuser)userdao.select(loginform.getemail());
           
            if(essuser==null){
            if(userdao.getbyuser("email",   loginform.getemail())!=null)
            {
          httpservletrequest.setattribute("error",   "输入的email已存在,请重新输入");
          target="addno";
            }else   if(userdao.getbyuser("username",loginform.getusername())!=null){
            httpservletrequest.setattribute("error","输入的用户名已存在,请重新输入");
              target="addno";
            }else{
            essuser   user=new   essuser();
            user.setuserid(loginform.getemail());
            user.setusername(loginform.getusername());
            user.setpassword(loginform.getpassword());
            user.setdepname(loginform.getdqname());
            user.setname(loginform.getname());
            user.setsex(loginform.getsex());
            user.setemail(loginform.getemail());
            user.setbirth(loginform.getyear()+"-"+loginform.getmonth()+"-"+loginform.getday());
            user.setidcardtype(loginform.getidcardtype());
            user.setidcard(loginform.getidcard());
            user.setaddress(loginform.getaddress());
            user.setofficephone(loginform.getofficephone());
            user.setotherphone(loginform.getotherphone());
            user.setcompany(loginform.getcompany());
            user.setanswer(loginform.getremark());
            userdao.insert(user);
            httpservletrequest.setattribute("error",   "用户注册成功");
            }
            }else{
        httpservletrequest.setattribute("error",   "输入的用户名已存在,请重新输入");
                target="addno";
            }
        }catch(exception   e){

        }
        return   actionmapping.findforward(target);
    }


插入操作的方法为:
  public   essuser   insert(essuser   obj)   {

        transaction   tx   =   null;
        try   {
            s   =   hibernateutil.currentsession();
            tx   =   s.begintransaction();

            s.save(obj);
            tx.commit();
        }
        catch   (hibernateexception   he)   {
            if   (tx   !=   null)   {
                try   {
                    tx.rollback();
                }
                catch   (hibernateexception   ex)   {
                }
            }
            log.debug(he);//报错的是这一行
        }
        finally   {
            try   {
                hibernateutil.closesession();
            }
            catch   (hibernateexception   expageid)   {
            }
        }
        return   obj;
    }


如果哪位遇到过这个问题或者知道怎么解决的话跟帖说声,也可留个qq或者msn,诚心请教!谢谢
发表于:2008-01-16 16:42:591楼 得分:0
按有几个群,你不妨加进去,可以和大家一起讨论啊.........46986340,28039577,4804620                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
在那里看看有无能回答你的,谢谢,lz,甭忘了给俺分哦,谢谢lz
发表于:2008-01-16 17:21:542楼 得分:0
不知道你查询的时候能不能正常查询出数据,
看你的报错信息感觉是包冲突,跟踪调试不行吗?

另外你的tx是不是为null啊?
发表于:2008-01-16 17:28:343楼 得分:0
登录的时候也不行,所以不能正常查询。
对于debug这个功能不是很了解
同时,在注册的页面,对email和user没有进行验证,就直接跳回到主页了,也就是return       actionmapping.findforward(target);  
发表于:2008-01-16 17:32:574楼 得分:0
对于包的问题,在tomcat启动时有这样一句话:
信息:   validatejarfile(e:\apache-tomcat-5.5.25\webapps\ygweb\web-inf\lib\servlet-2.3.jar)   -   jar   not   loaded.   see   servlet   spec   2.3,   section   9.7.2.   offending   class:   javax/servlet/servlet.class

不知道是不是这个原因?

ps:这个项目我是直接从同事那拷贝过来的,在他那里能够跑起来,可在我这里就出现了这个问题。我那同事已经辞职了,所以找不到他,所以发帖问了
发表于:2008-01-16 17:34:215楼 得分:0
debug功能很好用;
设置断点调试,f6执行、f5进入方法执行、f7跳出方法。

你先写个测试连接数据库的类,看看能不能正常查询数据库,总感觉报错信息怪怪的
try       {  
                        s       =       hibernateutil.currentsession();  
                        tx       =       s.begintransaction();  
                      //在这个位置看看tx是否为null                
                      s.save(obj);  
                        tx.commit();  
                }  
...
发表于:2008-01-16 17:40:176楼 得分:0
确实为null
发表于:2008-01-16 17:46:167楼 得分:0
<?xml   version="1.0"   encoding="utf-8"?>
<!doctype   hibernate-mapping   public   "-//hibernate/hibernate   mapping   dtd   2.0//en"   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class   name="com.sunyard.approve.bean.essuser"   table="essuser">
<id   name="userid"   column="userid"   type="string"   length="32">
<generator   class="assigned"/>
</id>
<property   name="email"   column="email"   type="string"   length="50"   />
<property   column="climecode"   length="20"   name="climecode"   type="string"/>
<property   column="climename"   length="32"   name="climename"   type="string"/>
<property   name="question"   column="question"   type="string"   length="200"/>
<property   name="answer"   column="answer"   type="string"   length="200"/>
<property   name="nickname"   column="nickname"   type="string"   length="50"/>
<property   name="name"   column="name"   type="string"   length="100"/>
<property   name="sex"   column="sex"   type="string"   length="50"/>
<property   name="birth"   column="birth"   type="string"   length="50"/>
<property   name="address"   column="address"   type="string"   length="200"/>
<property   name="msn"   column="msn"   type="string"   length="50"/>
<property   name="mobile"   column="mobile"   type="string"   length="50"/>
<property   name="qq"   column="qq"   type="string"   length="50"/>
<property   name="province"   column="province"   type="string"   length="50"/>
<property   name="city"   column="city"   type="string"   length="50"/>
<property   name="company"   column="company"   type="string"   length="100"/>
<property   name="companyaddress"   column="companyaddress"   type="string"   length="100"/>
<property   name="postalcode"   column="postalcode"   type="string"   length="50"/>
<property   name="contractphone"   column="contractphone"   type="string"   length="50"/>
<property   name="officephone"   column="officephone"   type="string"   length="50"/>
<property   name="homephone"   column="homephone"   type="string"   length="50"/>
<property   name="otherphone"   column="otherphone"   type="string"   length="50"/>
<property   name="nationality"   column="nationality"   type="string"   length="50"/>
<property   name="nativeplace"   column="nativeplace"   type="string"   length="50"/>
<property   name="culture"   column="culture"   type="string"   length="50"/>
<property   name="othermail"   column="othermail"   type="string"   length="100"/>
<property   name="idcard"   column="idcard"   type="string"   length="50"/>
<property   name="idcardtype"   column="idcardtype"   type="string"   length="50"/>
<property   name="othername"   column="othername"   type="string"   length="50"/>
<property   name="depname"   column="depname"   type="string"   length="100"/>
<property   name="umadminid"   column="umadminid"   type="string"   length="50"/>
<property   name="depid"   column="depid"   type="string"   length="20"/>
<property   name="canusemail"   column="canusemail"   type="string"   length="100"/>
<property   name="username"   column="username"   type="string"   length="50"/>
<property   name="password"   column="password"   type="string"   length="50"/>
<property   name="status"   column="status"   type="string"   length="1"/>

</class>
</hibernate-mapping>


发表于:2008-01-16 17:46:328楼 得分:0
<?xml   version="1.0"   encoding="utf-8"?>
<!doctype   hibernate-mapping   public   "-//hibernate/hibernate   mapping   dtd   2.0//en"   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class   name="com.sunyard.approve.bean.essuser"   table="essuser">
<id   name="userid"   column="userid"   type="string"   length="32">
<generator   class="assigned"/>
</id>
<property   name="email"   column="email"   type="string"   length="50"   />
<property   column="climecode"   length="20"   name="climecode"   type="string"/>
<property   column="climename"   length="32"   name="climename"   type="string"/>
<property   name="question"   column="question"   type="string"   length="200"/>
<property   name="answer"   column="answer"   type="string"   length="200"/>
<property   name="nickname"   column="nickname"   type="string"   length="50"/>
<property   name="name"   column="name"   type="string"   length="100"/>
<property   name="sex"   column="sex"   type="string"   length="50"/>
<property   name="birth"   column="birth"   type="string"   length="50"/>
<property   name="address"   column="address"   type="string"   length="200"/>
<property   name="msn"   column="msn"   type="string"   length="50"/>
<property   name="mobile"   column="mobile"   type="string"   length="50"/>
<property   name="qq"   column="qq"   type="string"   length="50"/>
<property   name="province"   column="province"   type="string"   length="50"/>
<property   name="city"   column="city"   type="string"   length="50"/>
<property   name="company"   column="company"   type="string"   length="100"/>
<property   name="companyaddress"   column="companyaddress"   type="string"   length="100"/>
<property   name="postalcode"   column="postalcode"   type="string"   length="50"/>
<property   name="contractphone"   column="contractphone"   type="string"   length="50"/>
<property   name="officephone"   column="officephone"   type="string"   length="50"/>
<property   name="homephone"   column="homephone"   type="string"   length="50"/>
<property   name="otherphone"   column="otherphone"   type="string"   length="50"/>
<property   name="nationality"   column="nationality"   type="string"   length="50"/>
<property   name="nativeplace"   column="nativeplace"   type="string"   length="50"/>
<property   name="culture"   column="culture"   type="string"   length="50"/>
<property   name="othermail"   column="othermail"   type="string"   length="100"/>
<property   name="idcard"   column="idcard"   type="string"   length="50"/>
<property   name="idcardtype"   column="idcardtype"   type="string"   length="50"/>
<property   name="othername"   column="othername"   type="string"   length="50"/>
<property   name="depname"   column="depname"   type="string"   length="100"/>
<property   name="umadminid"   column="umadminid"   type="string"   length="50"/>
<property   name="depid"   column="depid"   type="string"   length="20"/>
<property   name="canusemail"   column="canusemail"   type="string"   length="100"/>
<property   name="username"   column="username"   type="string"   length="50"/>
<property   name="password"   column="password"   type="string"   length="50"/>
<property   name="status"   column="status"   type="string"   length="1"/>

</class>
</hibernate-mapping>


发表于:2008-01-16 17:50:029楼 得分:0
<?xml   version='1.0'   encoding='utf-8'?>
<!doctype   hibernate-configuration   public
                    "-//hibernate/hibernate   configuration   dtd   2.0//en"
                    "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<!--   generated   by   myeclipse   hibernate   tools.                                       -->
<hibernate-configuration>

        <session-factory>
                <property   name="dialect"> net.sf.hibernate.dialect.oracle9dialect </property>
                <property   name="connection.driver_class"> oracle.jdbc.driver.oracledriver </property>
                <property   name="connection.username"> aaaa </property>
                <property   name="connection.password"> aaaa </property>

                <property   name="connection.url"> jdbc:oracle:thin:@127.0.0.1:1521:oradb </property>

        <property   name="connection.pool.size"> 1 </property>
                <property   name="statement_cache.size"> 25 </property>
                <property   name="jdbc.fetch_size"> 50 </property>
                <property   name="jdbc.batch_size"> 1 </property>
                <property   name="show_sql"> false </property>

                <!--   浠ヤ笅鏄熀鏈敤渚嬫ā鍧?   -->
                <mapping   resource="com/sunyard/qsis/bean/caseinfo/qscaseinfo.hbm.xml"/>
                <mapping   resource="com/sunyard/qsis/bean/caseinfo/qscaseex.hbm.xml"/>
                <mapping   resource="com/sunyard/qsis/bean/caseinfo/qsnodeinfo.hbm.xml"/>
                <mapping   resource="com/sunyard/qsis/bean/caseinfo/qsnodeex.hbm.xml"/>
                <mapping   resource="com/sunyard/qsis/bean/caseinfo/qsbusiflow.hbm.xml"/>
                <mapping   resource="com/sunyard/qsis/bean/caseinfo/casenodeinfo.hbm.xml"/>
.........
              </session-factory>

</hibernate-configuration>
发表于:2008-01-16 17:55:5510楼 得分:0
换个包试试servlet-2.3.jar
发表于:2008-01-16 18:00:5711楼 得分:0
错误信息不完整,不能判断,另外最好也看看dto,初步判断可能是数据库没开之类问题
发表于:2008-01-16 20:56:1012楼 得分:0
数据库已经确定开了,同时user   and   password   is   right,oracle是放在另外一台机器上的,非本机上
发表于:2008-01-17 10:13:0313楼 得分:0
数据库放到另一台机器那么
<property       name="connection.url">   jdbc:oracle:thin:@127.0.0.1:1521:oradb   </property>
这样行吗?
要写成那台机器的ip吧
发表于:2008-01-17 10:40:0714楼 得分:0
这个知道的。。。
发表于:2008-01-17 10:59:2115楼 得分:0
我上不了qq和msn
发表于:2008-01-17 15:33:2916楼 得分:0
请拿出错误信息的上下文
发表于:2008-01-18 09:47:3917楼 得分:0
错误信息:
2008-1-18   9:35:36   org.apache.catalina.core.aprlifecyclelistener   lifecycleevent
信息:   the   apache   tomcat   native   library   which   allows   optimal   performance   in   production   environments   was   not   found   on   the   java.library.path:   c:\sun\sdk\jdk\bin;e:\apache-tomcat-5.5.25\bin
2008-1-18   9:35:36   org.apache.coyote.http11.http11baseprotocol   init
信息:   initializing   coyote   http/1.1   on   http-3030
2008-1-18   9:35:36   org.apache.catalina.startup.catalina   load
信息:   initialization   processed   in   1282   ms
2008-1-18   9:35:36   org.apache.catalina.core.standardservice   start
信息:   starting   service   catalina
2008-1-18   9:35:36   org.apache.catalina.core.standardengine   start
信息:   starting   servlet   engine:   apache   tomcat/5.5.25
2008-1-18   9:35:36   org.apache.catalina.core.standardhost   start
信息:   xml   validation   disabled
2008-1-18   9:35:37   org.apache.catalina.core.applicationcontext   log
信息:   org.apache.webapp.balancer.balancerfilter:   init():   rulechain:   [org.apache.webapp.balancer.rulechain:   [org.apache.webapp.balancer.rules.urlstringmatchrule:   target   string:   news   /   redirect   url:   http://www.cnn.com],   [org.apache.webapp.balancer.rules.requestparameterrule:   target   param   name:   paramname   /   target   param   value:   paramvalue   /   redirect   url:   http://www.yahoo.com],   [org.apache.webapp.balancer.rules.accepteverythingrule:   redirect   url:   http://jakarta.apache.org]]
2008-1-18   9:35:38   org.apache.catalina.core.applicationcontext   log
信息:   contextlistener:   contextinitialized()
2008-1-18   9:35:38   org.apache.catalina.core.applicationcontext   log
信息:   sessionlistener:   contextinitialized()
2008-1-18   9:35:38   org.apache.catalina.core.applicationcontext   log
信息:   contextlistener:   contextinitialized()
2008-1-18   9:35:38   org.apache.catalina.core.applicationcontext   log
信息:   sessionlistener:   contextinitialized()
2008-1-18   9:35:39   org.apache.catalina.loader.webappclassloader   validatejarfile
信息:   validatejarfile(e:\apache-tomcat-5.5.25\webapps\ygweb\web-inf\lib\servlet-2.3.jar)   -   jar   not   loaded.   see   servlet   spec   2.3,   section   9.7.2.   offending   class:   javax/servlet/servlet.class
log4j:warn   no   appenders   could   be   found   for   logger   (org.apache.commons.digester.digester.sax).
log4j:warn   please   initialize   the   log4j   system   properly.
09:35:43,046   debug   sunforminitplugin:154   -   init   xslt   resource...
09:35:43,609   debug   sunforminitplugin:193   -   add   0   xslt   to   context
09:35:43,609   debug   sunforminitplugin:199   -   init   constant   table   ...
09:35:43,609     info   sunforminitplugin:218   -   init   globaledatasrc   definition   ...
09:35:43,625     info   sunforminitplugin:238   -   srcfilename   is:   e:\apache-tomcat-5.5.25\webapps\ygweb\web-inf\configs\global_datasrc_init.xml
09:35:43,625   error   globaldatasrcdef:87   -   srcfile:     is   not   exist!
09:35:43,625     info   globaldatasrcdef:96   -   reload   global   datasrc   file...
09:35:43,906   debug   methodvaluedefimpl:68   -   get   0   parameter   definitions!
09:35:43,906   debug   methodvaluedefimpl:68   -   get   0   parameter   definitions!
09:35:43,953   debug   methodvaluedefimpl:68   -   get   2   parameter   definitions!
.........
09:35:44,953   debug   methodvaluedefimpl:68   -   get   2   parameter   definitions!
09:35:44,953   debug   methodvaluedefimpl:68   -   get   1   parameter   definitions!
09:35:44,953   debug   methodvaluedefimpl:68   -   get   1   parameter   definitions!
09:35:45,015   debug   datasrcutils:130   -   get   212   datasrc   definitions!
09:35:45,015     info   globaldatasrcdef:104   -   reload   global   datasrc   file,   ok!
09:35:45,015     info   sunforminitplugin:240   -   init   globaledatasrc   definition,   ok!
服务器启动时@创建数据库索引   @
2008-1-18   9:35:45   org.apache.coyote.http11.http11baseprotocol   start
信息:   starting   coyote   http/1.1   on   http-3030
2008-1-18   9:35:46   org.apache.jk.common.channelsocket   init
信息:   jk:   ajp13   listening   on   /0.0.0.0:8009
2008-1-18   9:35:46   org.apache.jk.server.jkmain   start
信息:   jk   running   id=0   time=0/235     config=null
2008-1-18   9:35:46   org.apache.catalina.storeconfig.storeloader   load
信息:   find   registry   server-registry.xml   at   classpath   resource
2008-1-18   9:35:46   org.apache.catalina.startup.catalina   start
信息:   server   startup   in   10235   ms
------正在e:\apache-tomcat-5.5.25\webapps\ygweb\index下建立索引-----
09:36:30,281   debug   essuserdaohibernate:47   -   net.sf.hibernate.jdbcexception:   could   not   load:   [com.sunyard.approve.bean.essuser#123@163.com]
09:39:41,265   debug   essuserdaohibernate:84   -   net.sf.hibernate.jdbcexception:   could   not   insert:   [com.sunyard.approve.bean.essuser#123@163.com]
发表于:2008-01-20 01:21:5518楼 得分:0
应该是你驱动配置的问题,直连包导了没?配置都正确吗?
发表于:2008-01-20 18:36:5919楼 得分:0
包引了吗
驱动注册了吗
看错误提示应该是少包或者是类里少必须的方法
发表于:2008-01-21 00:13:5820楼 得分:0
java交流与学习群:45633778  
挑战技术,超越自我!!


快速检索

最新资讯
热门点击