Note that there are some explanatory texts on larger screens.

plurals
  1. POAspectj compile time weaving based transactions not working (JPA from a WebService call)
    text
    copied!<p>I'm trying to use aspectj with compile time weaving to support annotations like Spring's @Transactional and @Configurable. I'm using the org.springframework.orm.jpa.JpaTransactionManager transaction manager and what I see in the logs when I try to call entityManager.persist(entity) in my GenericDAO is something like this:</p> <pre><code>insurance-module-0.1-SNAPSHOT 19:57:55.199 [http-bio-8084-exec-49] TRACE org.hibernate.loader.Loader - Bound [6] parameters total insurance-module-0.1-SNAPSHOT 19:57:55.199 [http-bio-8084-exec-49] TRACE org.hibernate.loader.Loader - processing result set insurance-module-0.1-SNAPSHOT 19:57:55.199 [http-bio-8084-exec-49] DEBUG org.hibernate.loader.Loader - result set row: 0 insurance-module-0.1-SNAPSHOT 19:57:55.199 [http-bio-8084-exec-49] TRACE o.h.t.descriptor.sql.BasicExtractor - found [1] as column [id3_] insurance-module-0.1-SNAPSHOT 19:57:55.199 [http-bio-8084-exec-49] DEBUG org.hibernate.loader.Loader - result row: EntityKey[com.vendio.insurance.domain.db.InsuranceRate#1] insurance-module-0.1-SNAPSHOT 19:57:55.199 [http-bio-8084-exec-49] TRACE org.hibernate.loader.Loader - done processing result set (1 rows) insurance-module-0.1-SNAPSHOT 19:57:55.200 [http-bio-8084-exec-49] TRACE org.hibernate.loader.Loader - total objects hydrated: 0 insurance-module-0.1-SNAPSHOT 19:57:55.200 [http-bio-8084-exec-49] DEBUG o.h.e.StatefulPersistenceContext - initializing non-lazy collections insurance-module-0.1-SNAPSHOT 19:57:55.200 [http-bio-8084-exec-49] TRACE org.hibernate.impl.SessionImpl - after transaction completion insurance-module-0.1-SNAPSHOT 19:57:55.201 [http-bio-8084-exec-49] TRACE o.s.t.s.TransactionSynchronizationManager - Retrieved value [org.springframework.orm.jpa.EntityManagerHolder@5ec859c1] for key [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean@337cbe84] bound to thread [http-bio-8084-exec-49] insurance-module-0.1-SNAPSHOT 19:57:55.209 [http-bio-8084-exec-49] DEBUG org.hibernate.SQL - select sequence_next_hi_value from hibernate_sequences where sequence_name = 'registered_policy' for update insurance-module-0.1-SNAPSHOT 19:57:55.210 [http-bio-8084-exec-49] DEBUG org.hibernate.SQL - update hibernate_sequences set sequence_next_hi_value = ? where sequence_next_hi_value = ? and sequence_name = 'registered_policy' insurance-module-0.1-SNAPSHOT 19:57:55.218 [http-bio-8084-exec-49] TRACE o.s.t.s.TransactionSynchronizationManager - Retrieved value [org.springframework.orm.jpa.EntityManagerHolder@5ec859c1] for key [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean@337cbe84] bound to thread [http-bio-8084-exec-49] </code></pre> <p><strong>so the per-table hibernate sequence gets updated but my entity is not inserted into the database.</strong></p> <p>If I add entityManager.flush() an exception appears stating "<em>no transaction is in progress</em>".</p> <p><em>What is going on here?!</em></p> <p>My GenericDAO class looks like this:</p> <pre><code>public class GenericDAO&lt;T extends Persistable&gt; { @PersistenceContext protected EntityManager entityManager; @PersistenceUnit protected EntityManagerFactory entityManagerFactory; @Transactional public void saveOrUpdate(T entity) { entityManager.persist(entity); } } </code></pre> <p>I call the saveOrUpdate method from a web-service exported with the <a href="http://jax-ws-commons.java.net/spring/" rel="nofollow">WSSpringServlet</a>.</p> <p>P.S.: Also my Maven config looks like this:</p> <pre><code> &lt;plugin&gt; &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt; &lt;artifactId&gt;aspectj-maven-plugin&lt;/artifactId&gt; &lt;version&gt;1.4&lt;/version&gt; &lt;configuration&gt; &lt;complianceLevel&gt;1.6&lt;/complianceLevel&gt; &lt;showWeaveInfo&gt;true&lt;/showWeaveInfo&gt; &lt;aspectLibraries&gt; &lt;aspectLibrary&gt; &lt;groupId&gt;org.springframework&lt;/groupId&gt; &lt;artifactId&gt;spring-aspects&lt;/artifactId&gt; &lt;/aspectLibrary&gt; &lt;/aspectLibraries&gt; &lt;/configuration&gt; &lt;executions&gt; &lt;execution&gt; &lt;goals&gt; &lt;goal&gt;compile&lt;/goal&gt; &lt;/goals&gt; &lt;/execution&gt; &lt;/executions&gt; &lt;/plugin&gt; </code></pre> <p>When compiling I get something which looks decent enough (my aspect gets applied):</p> <pre><code> Join point 'method-call(void javax.persistence.EntityManager.persist(java.lang.Object))' in Type 'com.vendio.insurance.dao.GenericDAO' (GenericDAO.java:28) advised by afterThrowing advice from 'org.springframework.orm.jpa.aspectj.JpaExceptionTranslatorAspect' (spring-aspects-3.1.0.RELEASE.jar!JpaExceptionTranslatorAspect.class:14(from JpaExceptionTranslatorAspect.aj)) </code></pre> <p>And my relevant Spring config is:</p> <pre><code>&lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt; &lt;property name="entityManagerFactory" ref="entityManagerFactory"/&gt; &lt;/bean&gt; &lt;context:component-scan base-package="com.vendio.insurance" /&gt; &lt;context:spring-configured/&gt; &lt;!-- &lt;bean class="org.springframework.transaction.aspectj.AnnotationTransactionAspect" factory-method="aspectOf"&gt; &lt;property name="transactionManager" ref="transactionManager"/&gt; &lt;/bean&gt;--&gt; &lt;tx:annotation-driven mode="aspectj" transaction-manager="transactionManager" /&gt; </code></pre> <p>So everything looks decent, but I can't find an answer of why this doesn't work...</p>
 

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