jpa spring 事务配置 无法保存数据 事务提交不了。

这几天经理搭了个框架,但是事务出了点问题,架子用的是jpa2+spring 3 mvc ,但是配置完成后只能查询不能保存数据。

 

代码采用的是maven管理的。  工程分parent,util,web-util ,domain,app 等应用来完成。

 

这样有利于代码的分离管理。

 

 

app的pom.xml 为:(主要是说明用了哪些依赖jar包)

 

 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

 
  com.lsoba.parent
  com.lsoba
  0.0.1-SNAPSHOT
  ../parent
 

 4.0.0
 com.lsoba.main
 com.lsoba.main
 0.0.1-SNAPSHOT
 war

 com.lsoba.main
 http://maven.apache.org

 
  UTF-8
 

 
  
   spring-maven-release
   Spring Maven Release Repository
   http://maven.springframework.org/release
  

  
   spring-maven-milestone
   Spring Maven Milestone Repository
   http://maven.springframework.org/milestone
  

  
   spring-roo-repository
   Spring Roo Repository
   http://spring-roo-repository.springsource.org/release
  

 

 
  
   com.lsoba.domain
   com.lsoba.domain
   0.0.1-SNAPSHOT
  

  
   com.lsoba.util
   com.lsoba.util
   0.0.1-SNAPSHOT
  

  
   junit
   junit
  

  
   log4j
   log4j
  

  
   org.slf4j
   slf4j-api
  

  
   org.slf4j
   jcl-over-slf4j
  

  
   org.slf4j
   slf4j-log4j12
  

  
   org.aspectj
   aspectjrt
  

  
   org.aspectj
   aspectjweaver
  

  
   javax.servlet
   servlet-api
   provided
  

  
   net.sf.flexjson
   flexjson
  

  
   org.springframework
   spring-core
  

  
   org.springframework
   spring-test
   test
  

  
   org.springframework
   spring-context
  

  
   org.springframework
   spring-aop
  

  
   org.springframework
   spring-aspects
  

  
   org.springframework
   spring-tx
  

  
   com.h2database
   h2
  

  
   org.hibernate
   hibernate-core
  

  
   org.hibernate
   hibernate-entitymanager
  

  
   org.hibernate.javax.persistence
   hibernate-jpa-2.0-api
  

  
   org.hibernate
   hibernate-validator
  

  
   javax.validation
   validation-api
  

  
   cglib
   cglib-nodep
  

  
   javax.transaction
   jta
  

  
   org.springframework
   spring-jdbc
  

  
   org.springframework
   spring-orm
  

  
   commons-pool
   commons-pool
  

  
   commons-dbcp
   commons-dbcp
  

  
   org.apache.tiles
   tiles-core
  

  
   org.apache.tiles
   tiles-jsp
  

  
   org.springframework
   spring-web
  

  
   org.springframework
   spring-webmvc
  

  
   org.springframework.webflow
   spring-js-resources
  

  
   commons-digester
   commons-digester
  

  
   commons-fileupload
   commons-fileupload
  

  
   javax.servlet
   jstl
  

  
   javax.el
   el-api
   provided
  

  
   joda-time
   joda-time
  

  
   javax.servlet.jsp
   jsp-api
   provided
  

  
   org.springframework.security
   spring-security-core
  

  
   org.springframework.security
   spring-security-config
  

  
   org.springframework.security
   spring-security-web
  

  
   org.springframework.security
   spring-security-taglibs
  

 

 
  ${basedir}/src/main/java
  ${basedir}/Web/WEB-INF/classes
  
   
    ${basedir}/src/main/java
    
     **/*.java
    

   

  

  
   
    maven-war-plugin
    
     ${basedir}/Web
     ${basedir}/Web
    

   

   
    maven-compiler-plugin
    
     1.5
     1.5
    

   

  

 

 

 

web.xml配置如下:


 xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
 id="WebApp_ID" version="2.5">
 lsoba
 
  webAppRootKey
  lsoba.root
 

 
  defaultHtmlEscape
  true
 

 
  log4jConfigLocation
  classpath:META-INF/log4j.properties
 

 
  contextConfigLocation
  classpath*:META-INF/spring/applicationContext*.xml
 

 
  springSecurityFilterChain
  org.springframework.web.filter.DelegatingFilterProxy
 

 
  CharacterEncodingFilter
  org.springframework.web.filter.CharacterEncodingFilter
  
   encoding
   UTF-8
  

  
   forceEncoding
   true
  

 

 
  Spring OpenEntityManagerInViewFilter
  
   org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter

 

 
  Spring OpenEntityManagerInViewFilter
  /*
 

 
  springSecurityFilterChain
  /*
 

 
  CharacterEncodingFilter
  /*
 

 
  org.springframework.web.util.Log4jConfigListener
 

 
  org.springframework.web.context.ContextLoaderListener
 

 
  
   org.springframework.security.web.session.HttpSessionEventPublisher

 

 
  
   org.springframework.web.context.request.RequestContextListener

 

 
  appServlet
  org.springframework.web.servlet.DispatcherServlet
  
   contextConfigLocation
   classpath*:META-INF/spring/controllers-servlet.xml
  

  1
 

 
  appServlet
  /
 

 
  java.lang.NullPointerException
  /error/error.jsp
 

 
  404
  /error/404.jsp
 

 
  index.html
  index.htm
  index.jsp
  default.html
  default.htm
  default.jsp
 

 

 

 spring 的配置文件applicationContext.xml


 xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
 xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd   http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd   http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd   http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd   http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
 
 
 
 
 
 

 

   destroy-method="close">
  
  
  
  
 


   id="transactionManager">
  
 

   transaction-manager="transactionManager" />
   class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
  id="entityManagerFactory">
  
 

 

其它配置controllers-servlet.xml

 


 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
 xsi:schemaLocation="
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

 
   class="org.springframework.web.servlet.view.InternalResourceViewResolver">
     value="org.springframework.web.servlet.view.JstlView" />
  
  
 

 
 

 
   class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />
  

 

controllers.xml配置


 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
 xmlns:context="http://www.springframework.org/schema/context"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd  
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

 
 
  
 

 
 
 
 

 
 
 
 

 

主要原因就出在:

jee的支持上:

得在.classpath上加上


  
   
  

 

 
 

 

这样就ok了。事务也可以保存了。

 

 

哈哈。应该可以了,可以参考我的项目:http://www.lsoba.com

也可以去论坛留言。如果碰到问题可以去:http://bbs.lsoba.cn发问。有时间就可以一起学习讨论哈。

你可能感兴趣的:(jpa spring 事务配置 无法保存数据 事务提交不了。)