Comment #2 on issue 595 by [email protected]: PersistModule doesn't bind
interceptor for class-level @Transactional annotation
http://code.google.com/p/google-guice/issues/detail?id=595
A couple other concerns about guice-persist:
1. The javadoc for UnitOfWork.begin() specifies that "If there is already
[a session to the data layer] open, the invocation will do nothing. In this
way, you can define arbitrary units-of-work that nest within one another
safely." However, JpaPersistService.begin() throws IllegalStateException if
it's called twice on the same thread without a call to end() in between.
This seems to break the interface's contract.
However, if you have begin() do nothing if it a unit of work is already
open (which seems necessary by the contract), you'd need to ensure that
only the call to end() that matches the first call to begin actually closes
the session... perhaps keep a ThreadLocal count of the number of times
begin() is called and then count down again each time end() is called,
closing the session when end() has been called as many times as begin() was?
2. JpaPersistService.get() starts a UnitOfWork if one has not already been
started. It then does a checkState to ensure that a UnitOfWork has been
started, with a message indicating that the user should ensure that they
start a UnitOfWork before trying to get() an EntityManager. Since a
UnitOfWork is always started before this check, it'll never throw an
exception.
However, I think that the correct behavior here would be to throw the
exception rather than starting a UnitOfWork for the user. The problem is
that an EntityManager will be set in the ThreadLocal, but it probably will
not be removed because if the user didn't call UnitOfWork.begin() before
getting the EntityManager, they probably won't call UnitOfWork.end() after
either. This seems like a problem to me. The user should be required to use
UnitOfWork, or at least @Transactional (which ensures the UnitOfWork is
started and ended properly if one isn't started already), to manage the
lifetime of the session.
--
You received this message because you are subscribed to the Google Groups
"google-guice-dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-guice-dev?hl=en.