Last active
May 7, 2024 15:44
-
-
Save lol97/a40d060bdf0eedadd5cf9b2cd42af858 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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