Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JpaLocalTxnInterceptor is inconsistent. It uses both UnitOfWork and JpaPersistService #753

Open
gissuebot opened this issue Jul 7, 2014 · 1 comment

Comments

@gissuebot
Copy link

From guillaume.polet on June 05, 2013 04:23:12

Description of the issue: JpaLocalTxnInterceptor is inconsistent as it uses the "JpaPersistService emProvider" field to begin a transaction but uses the "UnitOfWork unitOfWork" to finish it. When the "UnifOfWork" binding of the JpaPersistModule is overriden, this causes incoherent states and eventually crashes.

Here is a class (I used nested class to keep a single java file) that reproduce the issue:
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Persistence;

import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.persist.PersistService;
import com.google.inject.persist.Transactional;
import com.google.inject.persist.UnitOfWork;
import com.google.inject.persist.jpa.JpaPersistModule;
import com.google.inject.util.Modules;

public class TestGuiceUnitOfWork {

        @Entity
        public static class MyEntity {
                @Id
                @GeneratedValue(strategy = GenerationType.AUTO)
                private Long id;

                @Column(name = "name")
                private String name;

                public Long getId() {
                        return id;
                }

                public void setId(Long id) {
                        this.id = id;
                }

                public String getName() {
                        return name;
                }

                public void setName(String name) {
                        this.name = name;
                }

        }

        @Singleton
        public static class EntityManagerFactoryProvider implements Provider<EntityManagerFactory>, PersistService {
                private EntityManagerFactory emFactory;

                @Override
                public EntityManagerFactory get() {
                        return emFactory;
                }

                @Override
                public void start() {
                        this.emFactory = Persistence.createEntityManagerFactory("my-pu");
                }

                @Override
                public void stop() {
                        emFactory.close();
                        emFactory = null;
                }
        }

        @Singleton
        public static class EntityManagerProvider implements Provider<EntityManager>, UnitOfWork {
                private final ThreadLocal<EntityManager> entityManager = new ThreadLocal<EntityManager>();
                @Inject
                private Provider<EntityManagerFactory> emf;

                @Override
                public EntityManager get() {
                        return entityManager.get();
                }

                @Override
&nbs...

Original issue: http://code.google.com/p/google-guice/issues/detail?id=753

@gissuebot
Copy link
Author

From sberlin on December 20, 2013 06:16:01

(No comment was entered for this change.)

Labels: Component-Persist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant