You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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;
@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();
}
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 {
@
Entitypublic 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;
}
}
@
Singletonpublic static class EntityManagerFactoryProvider implements Provider<EntityManagerFactory>, PersistService {
private EntityManagerFactory emFactory;
@
Overridepublic EntityManagerFactory get() {
return emFactory;
}
@
Overridepublic void start() {
this.emFactory = Persistence.createEntityManagerFactory("my-pu");
}
@
Overridepublic void stop() {
emFactory.close();
emFactory = null;
}
}
@
Singletonpublic static class EntityManagerProvider implements Provider<EntityManager>, UnitOfWork {
private final ThreadLocal<EntityManager> entityManager = new ThreadLocal<EntityManager>();
@
Injectprivate Provider<EntityManagerFactory> emf;
@
Overridepublic EntityManager get() {
return entityManager.get();
}
@
Override&nbs...
Original issue: http://code.google.com/p/google-guice/issues/detail?id=753
The text was updated successfully, but these errors were encountered: