Created
June 17, 2015 10:45
-
-
Save mrserverless/4838f037f4cba259d816 to your computer and use it in GitHub Desktop.
Dropwizard @UnitOfWork with Manual Transactions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@GET | |
@Path("/update") | |
@UnitOfWork(transactional = false) | |
public World update(World world) { | |
return transactionDao.updatesWorld(world); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Class TransactionDAO extends extends AbstractDAO<World> { | |
@Override | |
public World updatesQueries(World world) { | |
World world = null; | |
Transaction transaction = currentSession().beginTransaction(); | |
try { | |
world = persist(world); | |
transaction.commit(); | |
} catch (Exception e) { | |
transaction.rollback(); | |
throw new RuntimeException(e); | |
} | |
return world; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment