Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring jpa transaction business to Dao
    primarykey
    data
    text
    <p><strong>business layer:</strong></p> <pre><code>public class ServiceImpl implements Service{ @Transactional(readOnly = false) public void createOrUpdateAppPing(String s) { servicePingDao.createOrUpdateAppPing(s); } } </code></pre> <p><strong>Dao layer</strong> </p> <pre><code>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(); } </code></pre> <p>here : ** pingScService has select query ** updateScConfig - update query ** createScConfig-insert</p> <pre><code> config service-datasorce.xml &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;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 "&gt; &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt; &lt;property name="persistenceUnitName" value="smx4" /&gt; &lt;property name="jpaVendorAdapter" ref="jpaAdapter" /&gt; &lt;property name="dataSource" ref="dataSource" /&gt; &lt;/bean&gt; &lt;bean id="jpaAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt; &lt;property name="databasePlatform" value="com.luthresearch.savvyconnect.model.PostgreSQLDialectUuid" /&gt; &lt;property name="showSql" value="true" /&gt; &lt;property name="generateDdl" value="true" /&gt; &lt;/bean&gt; &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt; &lt;property name="driverClassName" value="${database.driver.class}" /&gt; &lt;property name="url" value="${database.savvyconnect.url}" /&gt; &lt;property name="username" value="${database.savvyconnect.username}" /&gt; &lt;property name="password" value="${database.savvyconnect.password}" /&gt; &lt;/bean&gt; &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt; &lt;property name="entityManagerFactory" ref="entityManagerFactory"/&gt; &lt;/bean&gt; IN service.xml &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;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"&gt; &lt;bean id="service" class="com.services.impl.SServicempl" autowire="byName"&gt; &lt;/bean&gt; &lt;tx:annotation-driven transaction-manager="transactionManager"/&gt; &lt;/beans&gt; </code></pre> <p>Now i want to add transaction support at service layer ...How i can do this.</p> <p>I tried adding <code>@Transaction</code> annotation but I am getting</p> <blockquote> <p>javax.persistence.TransactionRequiredException: Executing an update/delete query</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload