Spring Transaction

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 thrown:

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 propagating? Can anyone help me?

    
asked by anonymous 02.09.2015 / 16:21

1 answer

0

The problem has nothing to do with Spring itself. The exception indicates that you are passing an object with the id set to the persist method. When the object has an id set but has not been loaded by the EntityManager, we say that it is in the detached state.

    
13.09.2015 / 20:18