Весенняя сделка JPA бизнес на Дао - PullRequest
1 голос
/ 20 августа 2011

бизнес-уровень:

public class ServiceImpl implements Service{

  @Transactional(readOnly = false)
   public void createOrUpdateAppPing(String s) {

      servicePingDao.createOrUpdateAppPing(s);
   }
}

слой Дао

public   void createOrUpdateAppPing(String sc) {
      EntityManager  entityManager = entityManagerFactory.createEntityManager();    
          pingScService(sc,entityManager);
          if(ifHasPingScConfig(sc,entityManager)) {
             updateScConfig(sc,entityManager);
          } else {
             createScConfig(sc,entityManager);      }
         entityManager.close();    
   }

здесь: ** pingScService имеет запрос выбора ** updateScConfig - запрос на обновление ** createScConfig-insert

 config service-datasorce.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:osgi="http://www.springframework.org/schema/osgi"
    xmlns:osgix="http://www.springframework.org/schema/osgi-compendium"
    xmlns:ctx="http://www.springframework.org/schema/context"   
    xsi:schemaLocation="
    http://www.springframework.org/schema/osgi
          http://www.springframework.org/schema/osgi/spring-osgi.xsd
    http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context 
      http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/osgi-compendium 
      http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd     
       ">

       <bean id="entityManagerFactory"
            class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
            <property name="persistenceUnitName" value="smx4" />
            <property name="jpaVendorAdapter" ref="jpaAdapter" />
            <property name="dataSource" ref="dataSource" />
        </bean>

        <bean id="jpaAdapter"
            class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="databasePlatform" value="com.luthresearch.savvyconnect.model.PostgreSQLDialectUuid" />
            <property name="showSql" value="true" />
            <property name="generateDdl" value="true" />
    </bean> 
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">       
            <property name="driverClassName" value="${database.driver.class}" />        
            <property name="url"             value="${database.savvyconnect.url}" />
            <property name="username"        value="${database.savvyconnect.username}" />
            <property name="password"        value="${database.savvyconnect.password}" />

    </bean>



        <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>

  </bean>


  IN service.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:osgi="http://www.springframework.org/schema/osgi"
       xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans.xsd
                        http://www.springframework.org/schema/osgi
                        http://www.springframework.org/schema/osgi/spring-osgi.xsd
                               http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">


    <bean id="service"
        class="com.services.impl.SServicempl" autowire="byName">

    </bean>
            <tx:annotation-driven transaction-manager="transactionManager"/>
  </beans>

Теперь я хочу добавить поддержку транзакций на уровне сервиса ... Как я могу это сделать.

Я пытался добавить @Transaction аннотацию, но получаю

javax.persistence.TransactionRequiredException: выполнение запроса на обновление / удаление

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...