Skip to content

Add @UnitOfWork annotation #731

@gissuebot

Description

@gissuebot

From spootsy.ootsy on October 05, 2012 00:28:48

Something that seems to be missing from guice-persist is a @UnitOfWork equivalent to the @Transactional annotation. One that will automatically start/stop a UnitOfWork as required, but not begin/commit a transaction.

Our use case: we have a bunch of classes that are used for database access. We use these in command-line applications, both during initialisation (in provider methods) and at run-time.

If a method exists for altering data in the database, we can happily apply @Transactional to it. It can now be safely called whether you're in an active UnitOfWork or not (because @Transactional will only start/stop a UnitOfWork if required).

For methods that only read data from the database, we don't want to start/commit transactions needlessly, so the @Transactional tag is a no-go. But - we have no means of guaranteeing that a method is encapsulated by a UnitOfWork automatically... there's no way to check if a UnitOfWork is already running, so there's no way to start/stop one only as required.

Would be a boon to have this functionality. Alternatively, an "isRunning()" method on UnitOfWork would make it possible for us (and others) to create our own automatic UnitOfWork controllers.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions