Transaction in the Spring

Asked

Viewed 55 times

0

I want to know more about transactions in spring. I have the following structure:

My Service:

@Service
@Transactional
public class MinhaClasseServiceImpl implements MinhaClasseService {

    @Autowired
    private MinhaClasseDao minhaClasseDao;

    @Autowired
    private OutraClasseDao outraClasseDao;

    @Autowired
    private MaisOutraClasseDao maisOutraClasseDao;

    public void salvarMinhaClasse(final MinhaClasse minhaClasse) throws Exception {
           maisOutraClasseDao.salvarMaisOutraClasse(minhaClasse().getOutraClasse().getMaisOutraClasse());
           outraClasseDao.salvarOutraClasse(minhaClasse().getOutraClasse());
           minhaClasseDao.salvarminhaClasse(minhaClasse());
    }

}

But when saving, an exception is made:

11:11:33,766 ERROR [stderr] (default task-13) javax.persistence.PersistenceException: 
org.hibernate.PersistentObjectException: detached entity passed to persist: 
com.teste.entity.MaisOutraClasse

Is the transaction not spreading? Can someone help me?

1 answer

0

The problem is not about Spring itself. Exception indicates that you are passing an object with the id set to the persist method. When the object has an id set, but was not loaded by Entitymanager, we say it is in the Detached state.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.