Hi,
we have a Dropwizard app that includes some cli commands which do not
expose a Web API (i.e. there is no Jersey resource).
What I would like to accomplish is to use the annotation @UnitOfWork on
some methods invoked by these cli commands that need to connect to the DB
via Hibernate. This instead of managing the transaction to the DB ourselves
(which we are able to do, tested and works).
My attempt was to instantiate the class where such methods are implemented,
with a UnitOfWorkAwareProxyFactory, similarly to what I already
successfully done when annotating class invoked by Jersey resources.
Unfortunately, this time I could not make it work and when my DAO tries to
create a Hibernate criteria the following exception gets thrown:
Exception in thread "main" org.hibernate.HibernateException: createCriteria
is not valid without active transaction
at org.hibernate.context.internal.
ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(
ThreadLocalSessionContext.java:352)
at com.sun.proxy.$Proxy82.createCriteria(Unknown Source)
at com.abc.foo.db.MyDAO.getEarliestArrival(MyDAO.java:231)
This confuses me because when I debugged the application, I can see that
the UnitOfWork's code gets executed and both an Hibernate session and a
Transaction get open. However, obviously when the ThreadLocalSessionContext
throws the exception, its real session doesn't have an active transaction..
Are there any known limitation for using the UnitOfWork in cli commands? Or
can they be used at all? Do they need some special tuning in respect to
what I am used to do with the UnitOfWorkAwareProxyFactory?
Any help is appreciated,
thanks in advance.
--
You received this message because you are subscribed to the Google Groups
"dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.