1

我使用 Spring 3.0.6、GlassFish 3.1、EJB 3、JPA 2,我的提供者是 EclipseLink (JPA 2.0)

我的 webApplication 有这些配置文件:

持久性.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="ejb_transportPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>tranEnterprise</jta-data-source>    
  <properties>
  <property name="eclipselink.target-server" value="SunAS9"/>
  <property name="eclipselink.logging.level" value="FINEST"/>
  <property name="eclipselink.target-database" value="org.eclipse.persistence.platform.database.MySQLPlatform"/>
</properties>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
</persistence-unit>
</persistence>

应用程序上下文.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:p="http://www.springframework.org/schema/p"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:aop="http://www.springframework.org/schema/aop"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xsi:schemaLocation="
   http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/aop
   http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
   http://www.springframework.org/schema/tx 
   http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
   http://www.springframework.org/schema/context 
   http://www.springframework.org/schema/context/spring-context-3.0.xsd 
   ">


<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="tranEnterprise"/>
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="persistenceUnitName" value="ejb_transportPU"/>
    <property name="loadTimeWeaver">
        <bean class="org.springframework.instrument.classloading.glassfish.GlassFishLoadTimeWeaver"/>
    </property>
    <property name="jpaVendorAdapter">
        <bean
        class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
        <property name="showSql" value="true" />
    </bean>
</property>
<property name="jpaDialect">
    <bean
        class="org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect" />
</property>
</bean>
<tx:jta-transaction-manager />
<bean id="persistenceAnnotation" class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
</beans>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
    30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>redirect.jsp</welcome-file>
</welcome-file-list>
</web-app>

我的控制器方法:

 @Transactional
    @RequestMapping(method = RequestMethod.POST)
    public String onSubmit(@ModelAttribute("contract") Contract contract)
    {
        try
        {
            contractBean.creatCotract(contract);                
        } catch (Exception e)
        {
            e.printStackTrace();
        }
        return "someThing";
    }

该项目显示数据,但不将数据保存在数据库中。我搜索了一周,但找不到任何答案。

4

1 回答 1

0

你不见了<tx:annotation-driven />

于 2012-09-16T16:19:28.517 回答