You can go the straight guice persistence route and simply use your
modules and bindings as per usual
The annotations will be very familiar in this regard
You can go the straight guice persistence route and simply use your
modules and bindings as per usual
The annotations will be very familiar in this regard
<dependency> <groupId>com.guicedee.services</groupId> <artifactId>guice-persist</artifactId> </dependency>
module my.module{ provides IGuiceModule with MyJpaPersistModule; } public class MyJpaPersistModule extends JpaPersistModule { public MyJpaPersistModule() { super("myFirstJpaUnit"); } }Finally, you must decide when the persistence service is to be started by invoking start() on PersistService. I typically use a simple initializer class that I can trigger at a time of my choosing:
public class MyInitializer { @Inject MyInitializer(PersistService service) { service.start(); // At this point JPA is started and ready. } }
@Transactional @Transactional(rollbackOn = { IOException.class, RuntimeException.class, ... }) @Transactional(rollbackOn = IOException.class, ignore = FileNotFoundException.class) public void myMethod() { ... }A unit of work is roughly the lifespan of an EntityManager (in JPA). It is the session referred to in the session-per-* strategies.
public class MyBackgroundWorker { @Inject private UnitOfWork unitOfWork; public void doSomeWork() { unitOfWork.begin(); try { // Do transactions, queries, etc... //... } finally { unitOfWork.end(); } } }