开发者社区> 问答> 正文

运行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" />

展开
收起
云栖技术 2016-06-02 14:41:09 2174 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
Well-That-Escalated-Quickly-How-Abusing-The-Docker-API-Led-To-Remote-Code-Execution-Same-Origin-Bypass-And-Persistence 立即下载
OPEN SOURCE IN A DATA-DRIVEN WORLD 立即下载
低代码开发师(初级)实战教程 立即下载