Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7075729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:12:44+00:00 2026-05-28T06:12:44+00:00

I’ve been teaching myself Spring 3.0 by implementing a JavaEE Web-app using: Tomcat 7

  • 0

I’ve been teaching myself Spring 3.0 by implementing a JavaEE Web-app using:

  • Tomcat 7
  • Spring 3.0, Security 3.1
  • JPA: EclipseLink 2.3.1
  • MySQL 5.5, Connector/J 5.1

My problem is:

  • I’ve set up declarative transaction management on my service layer using Spring AOP.
  • (I also have a Spring AOP logging interceptor, declared in the same place.)
  • Creating new entities isn’t a problem.
  • Updating existing entities is!
  • According to the log, the service method returns before the transaction begins!

    [org.springframework.orm.jpa.JpaTransactionManager] - <Using transaction object [org.springframework.orm.jpa.JpaTransactionManager$JpaTransactionObject@335f5e3a]>
    [org.springframework.orm.jpa.JpaTransactionManager] - <Creating new transaction with name [org.snowjak.livesavegive.data.service.TagService.rename]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT>
    [org.springframework.orm.jpa.JpaTransactionManager] - <Opened new EntityManager [org.eclipse.persistence.internal.jpa.EntityManagerImpl@3a234c2f] for JPA transaction>
    [org.springframework.orm.jpa.JpaTransactionManager] - <Exposing JPA transaction as JDBC transaction [SimpleConnectionHandle: com.mysql.jdbc.JDBC4Connection@49116f61]>
    [myproject.data.service.MyEntityService] - <Beginning method: rename>
    [myproject.data.dao.MyEntityDao] - <Beginning method: get>
    [myproject.data.dao.MyEntityDao] - <After method: get>
    [myproject.data.dao.AbstractDao] - <Beginning method: update>
    [myproject.data.dao.AbstractDao] - <After method: update>
    [myproject.data.service.MyEntityService] - <After method: rename>
    [org.springframework.orm.jpa.JpaTransactionManager] - <Triggering beforeCommit synchronization>
    [org.springframework.orm.jpa.JpaTransactionManager] - <Triggering beforeCompletion synchronization>
    [org.springframework.orm.jpa.JpaTransactionManager] - <Initiating transaction commit>
    [org.springframework.orm.jpa.JpaTransactionManager] - <Committing JPA transaction on EntityManager [org.eclipse.persistence.internal.jpa.EntityManagerImpl@3a234c2f]>
    [org.springframework.orm.jpa.JpaTransactionManager] - <Triggering afterCommit synchronization>
    [org.springframework.orm.jpa.JpaTransactionManager] - <Triggering afterCompletion synchronization>
    [org.springframework.orm.jpa.JpaTransactionManager] - <Closing JPA EntityManager [org.eclipse.persistence.internal.jpa.EntityManagerImpl@3a234c2f] after transaction>
    
  • This inability-to-update disappears if I make my DAOs transactional, not my service-layer.

  • But The Authorities say that that’s Bad Style.

Can anyone offer any pointers/tips/tricks/secrets of the guild?

Edit:

I’ve turned on DEBUG detail for org.springframework in my logger; and see that, from what I can tell, transactions are being handled correctly after all — i.e., being begun before and ended after the service method in question.

I still have a problem updating, viz. my updates don’t appear in the PU nor the DB; now why would that be? …

Edit:

I’ve also peeked into the MySQL general-log while I made my update attempt. JPA, it seems, simply isn’t issuing UPDATEs to the database!

==================================================================================

Entities:

  • Under myproject.data.entity. Nothing special. Generic JPA.

    @Entity
    public class MyEntity implements Serializable {
        @Id
        @GeneratedValue(strategy=GenerationType.AUTO)
        int id;
    
        @Column(nullable=false, unique=true)
        String name;
    
        ...
    }
    

DAOs:

Interfaces under myproject.data.dao.

  • interface AbstractDao

    @Repository
    interface AbstractDao<T,K> extends Serializable {
        public T get(K key);
        public Collection<T> getAll();
    
        public T save(T entity);
        public T update(T entity);
    }
    
  • interface MyEntityDao

    @Repository
    interface MyEntityDao extends AbstractDao<MyEntity, Integer> {
        public MyEntity get(String name);
    }
    

Implementation under myproject.data.dao.jpa.

  • abstract class AbstractDaoJpa

    @Repository
    abstract class AbstractDaoJpa implements AbstractDao<T,K> {
        protected EntityManager em;
        @PersistenceContext
        public void setEntityManager(EntityManager entityManager) {
            em = entityManager;
        }
    
        public T save(T entity) {
            em.persist(entity);
            return entity;
        }
    
        public T update(T entity) {
            return em.merge(entity);
        }
    }
    
  • class MyEntityDaoJpa extends AbstractDaoJpa implements MyEntityDao

    @Repository
    class MyEntityDaoJpa extends AbstractDaoJpa<MyEntity,Integer> implements MyEntityDao {
        @Override
        public MyEntity get(Integer key) {
            return em.find(MyEntity.class, key);
        }
    
        @Override
        public MyEntity get(String name) {
            return em.createQuery("select E from MyEntity E where E.name = :name", MyEntity.class).setParameter("name", name).getSingleResult();
        }
    
        ...
    }
    

Service layer:

Interfaces under myproject.data.service

  • interface EntityService

    @Service
    public interface EntityService<T> extends Serializable {
        public Collection<T> getAll();
    }
    
  • interface MyEntityService extends EntityService

    @Service
    public interface MyEntityService extends EntityService<MyEntity> {
        public MyEntity create(String name);
        public MyEntity get(String name);
    
        public MyEntity rename(String name);
    
        ...
    }
    

Implementation under myproject.data.service.impl

  • class MyEntityServiceImpl implements MyEntityService

    @Service
    public class MyEntityServiceImpl implements MyEntityService {
        private MyEntityDao dao;
    
        public MyEntityServiceImpl(MyEntityDao newDao) {
            dao = newDao;
        }
    
        @Override
        public MyEntity create(String name) {
            MyEntity e = new MyEntity();
            e.name = name;
            ...
            return dao.save(e);
        }
    
        ...
    
        @Override
        public MyEntity rename(String oldName, String newName) {
            MyEntity e = dao.get(oldName);
            e.name = newName;
            dao.update(e); // An attempt to fix by explicitly merging the modified entity.
                           // Didn't fix the problem.
            return e;
        }
    
        ...
    }
    

Spring configuration:

...

[ Declaration of DAOs and Service beans. Appropriate DAOs are injected into Service beans. ]

...

<!-- Tomcat-managed DataSource lookup via JNDI -->
<jee:jndi-lookup id="dataSource" jndi-name="jdbc/myDS"/>

<!-- Configure the EntityManagerFactory -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="loadTimeWeaver">
        <bean class="org.springframework.instrument.classloading.ReflectiveLoadTimeWeaver"/>
    </property>
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter"/>
    </property>
</bean>

<!-- Create the Transaction Manager -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>

<!-- Configure the Transaction Manager for AOP -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
        <!-- Some methods are read-only. -->
        <tx:method name="get*" read-only="true" propagation="SUPPORTS"/>
        <!-- All others, use defaults. -->
        <tx:method name="*"/>
    </tx:attributes>
</tx:advice>

...

<!-- Configure Spring AOP -->
<aop:config>
    <aop:pointcut id="wholeProject" expression="within(myproject..*)"/>
    <aop:pointcut id="serviceLayerOperation" expression="execution(* myproject.data.service.*.*(..))"/>

    <!-- Configure transaction management. -->
    <aop:advisor advice-ref="txAdvice" order="1" pointcut-ref="serviceLayerOperation"/>

    <!-- Configure logging interceptor. -->
    ...
</aop:config>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:12:45+00:00Added an answer on May 28, 2026 at 6:12 am

    The problem comes from the fact that you’re accessing the fields of your entity directly, without going through getters/setters.

    Using public fields is a very bad practice, because it breaks encapsulation. EclipseLink seems to need methods, probably becauseit’s weaving consists in adding byte-code into the methods. By accessing the fields directly, you must bypass the bytecode additions that make EclipseLink work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
We're building an app, our first using Rails 3, and we're having to build
I am using Paperclip to handle profile photo uploads in my app. They upload
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have thousands of HTML files to process using Groovy/Java and I need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.