Skip to content

Commit

Permalink
Handle already active transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
isabellerobin committed Feb 3, 2020
1 parent a9edcdb commit 72efa04
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public BaseEntityRepositoryImpl(EntityManager em) {
public BaseEntity save(BaseEntity entity) throws DataBaseException{
EntityTransaction tr = em.getTransaction();
try {
tr.begin();
if(!tr.isActive())
tr.begin();

if (entity.getId() == null) {
em.persist(entity);
} else {
Expand All @@ -40,7 +42,9 @@ public BaseEntity save(BaseEntity entity) throws DataBaseException{
public void delete(BaseEntity entity) throws DataBaseException {
EntityTransaction tr = em.getTransaction();
try {
em.getTransaction().begin();
if (!tr.isActive())
tr.begin();

if (em.contains(entity)) {
em.remove(entity);
}
Expand Down

0 comments on commit 72efa04

Please sign in to comment.