不想用这个账号了
2015-07-25 10:36
采纳率: 50%
浏览 3.5k
已采纳

运行getHibernateTemplate().save(xxx)时报错等问题 两天了坐等

2015-7-25 18:29:33 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [RegisterServlet] in context with path [/FirstHRD1] threw exception
java.lang.NullPointerException
at com.reitgn.dao.impl.AdvancedRegistrationDaoImpl.addAdvancedRegistration(AdvancedRegistrationDaoImpl.java:34)
at com.reitgn.service.impl.AdvanceRegistrationServiceImpl.addAdvancedRegistration(AdvanceRegistrationServiceImpl.java:34)
at com.reitgn.servlet.RegisterServlet.doPost(RegisterServlet.java:71)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2476)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2465)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:662)

我的想法:
Hibernate:DaoImpl类继承HibernateDaoSupport,使用getHibernateTemplate()或者Session操作数据。
Spring:加进去什么都不干,就是使用C3P0。
Servlet:控制等等。
帮忙看看我的applicationContext.xml对不对:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"

xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
http://www.springframework.org/schema/aop 
http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-4.1.xsd">


<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="url" value="jdbc:mysql://localhost:3306/firsthrd">
    </property>
    <property name="username" value="root"></property>
    <property name="password" value="518wsgtc"></property>
</bean>

<bean id="sessionFactory"
    class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource">
        <ref bean="dataSource" />
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">
                org.hibernate.dialect.MySQLDialect
            </prop>
        </props>
    </property>
    <property name="mappingResources">
        <list>
            <value>com/reitgn/entity/AdvancedRegistration.hbm.xml</value>
            <value>com/reitgn/entity/CurrentWorkUnit.hbm.xml</value>
            <value>com/reitgn/entity/ChinaQualification.hbm.xml</value>
            <value>com/reitgn/entity/InternationalQualification.hbm.xml</value>
            <value>com/reitgn/entity/Recommended.hbm.xml</value>
        </list>
    </property>
</bean>
<bean id="transactionManager"
    class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
        <tx:method name="save*" propagation="REQUIRED" /> <!-- 支持当前事务,如果执行到save开头的任何方法时没有事务则开启一个事务 这是最常见的方式 -->
        <tx:method name="add*" propagation="REQUIRED" />
        <tx:method name="delete*" propagation="REQUIRED" />
        <tx:method name="update*" propagation="REQUIRED" />
        <tx:method name="revise*" propagation="REQUIRED" />
        <tx:method name="find*" propagation="SUPPORTS" read-only="true" /> <!-- 支持当前事务,如果当前没有事务,就以非事务方式执行。只读 -->
        <tx:method name="get*" propagation="SUPPORTS" read-only="true" />
    </tx:attributes>
</tx:advice>
<aop:config>
    <aop:pointcut id="productServiceMethods"
        expression="execution(* com.reitgn.service.impl.*.*(..))" />
    <aop:advisor advice-ref="txAdvice" pointcut-ref="productServiceMethods" />
</aop:config>

目录结构:
图片说明

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

7条回答 默认 最新

  • 不想用这个账号了 2015-10-04 04:24
    已采纳

    java.lang.NoSuchMethodError:org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session

    hibernate 4 中没有 HibernateDaoSupport,包括数据访问都不需要 hibernatetemplate,必须改写 dao,直接使用 hibernate 的 session 和 query 接口。

    我使用了 Hibernate 4 的同时使用了 getHibernateTemplate().save(xxx) 所以报错找不出原因,可以的话将 Hibernate 3 中对应的 jar 包复制过来覆盖一下或者复制 jar 里面的方法,改写 Hibernate 4 的 jre,具体百度。

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • 查看更多回答(6条)

相关推荐 更多相似问题