Skip to content

Instantly share code, notes, and snippets.

@lol97
Last active May 7, 2024 15:44
Show Gist options
  • Select an option

  • Save lol97/a40d060bdf0eedadd5cf9b2cd42af858 to your computer and use it in GitHub Desktop.

Select an option

Save lol97/a40d060bdf0eedadd5cf9b2cd42af858 to your computer and use it in GitHub Desktop.
package com.sufyan97.learn_hibernate.warganegara;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@Service
public class WargaNegaraService {
@Autowired
private WargaNegaraRepository wargaNegaraRepository;
@Autowired
private PasporRepository pasporRepository;
@Transactional(propagation = Propagation.REQUIRED)
public void Store(WargaNegara wargaNegara) {
if(wargaNegara != null && wargaNegara.getPaspor() != null) {
Paspor paspor = wargaNegara.getPaspor();
pasporRepository.save(paspor);
}
wargaNegaraRepository.save(wargaNegara);
}
@Transactional(propagation = Propagation.REQUIRED)
public void destroy(WargaNegara wargaNegara) {
wargaNegaraRepository.delete(wargaNegara);
}
@Transactional(propagation = Propagation.REQUIRED)
public void removePaspor(WargaNegara wargaNegara) {
pasporRepository.delete(wargaNegara.getPaspor());
wargaNegara.setPaspor(null);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment