0
entityManager.remove() 함수를 처리 할 수 없습니다.
개체를 삭제하려고하면 오류 및 예외가 발생하지 않지만 레코드가 데이터베이스에 남아 있습니다.Spring JPA : entityManager remove not working
여기 내 EntityManager의 정의입니다 :
@Service
@ComponentScan(basePackages = {"pl.lodz.p.admin.service"})
@Transactional(rollbackFor = AccountException.class, propagation = Propagation.REQUIRES_NEW)
public class AccountServiceImpl implements AccountService {
@Autowired
AccountRepository accountRepository;
@Override
public void deleteAccountByLogin(String login) {
Account account = accountRepository.findByLogin(login);
accountRepository.delete(account);
}
}
그리고 저장소 :
@Repository("adminAccountRepository")
@Transactional(propagation = Propagation.MANDATORY)
public class AccountRepositoryImpl implements AccountRepository {
@PersistenceContext(unitName = "adminManager")
private EntityManager em;
@Override
public Account findByLogin(String login) {
Query query = em.createNamedQuery("Account.findByLogin");
query.setParameter("login", login);
Account account = (Account) query.getSingleResult();
return account;
}
@Override
public void delete(Account account) {
try {
em.remove(account);
} catch (Exception e) {
e.getCause();
}
}
}
왜 'em.remove (em.merge (account));'하고 있습니까? – smsnheck
삭제하는 것을 잊었습니다. em.remove (계정)이어야합니다. – piotrb