изменён метод удаления
This commit is contained in:
parent
cfeaf090f8
commit
7f64c30cb2
@ -18,9 +18,6 @@ public class CreatorService {
|
|||||||
@PersistenceContext
|
@PersistenceContext
|
||||||
private EntityManager em;
|
private EntityManager em;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
MangaService mangaService;
|
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Creator findCreator(Long id) {
|
public Creator findCreator(Long id) {
|
||||||
final Creator creator = em.find(Creator.class, id);
|
final Creator creator = em.find(Creator.class, id);
|
||||||
|
@ -6,6 +6,7 @@ import jakarta.persistence.EntityManager;
|
|||||||
import jakarta.persistence.EntityNotFoundException;
|
import jakarta.persistence.EntityNotFoundException;
|
||||||
import jakarta.persistence.PersistenceContext;
|
import jakarta.persistence.PersistenceContext;
|
||||||
import jakarta.transaction.Transactional;
|
import jakarta.transaction.Transactional;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
@ -15,6 +16,8 @@ import java.util.List;
|
|||||||
public class ReaderService {
|
public class ReaderService {
|
||||||
@PersistenceContext
|
@PersistenceContext
|
||||||
private EntityManager em;
|
private EntityManager em;
|
||||||
|
@Autowired
|
||||||
|
private MangaService mangaService;
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Reader findReader(Long id) {
|
public Reader findReader(Long id) {
|
||||||
@ -50,7 +53,13 @@ public class ReaderService {
|
|||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void removeManga(Manga manga, Long readerId) {
|
public void removeManga(Manga manga, Long readerId) {
|
||||||
em.createNativeQuery("delete from Mangas_Readers where MANGA_FK = " + manga.getId() + " AND READER_FK = "+ readerId).executeUpdate();
|
//em.createNativeQuery("delete from Mangas_Readers where MANGA_FK = " + manga.getId() + " AND READER_FK = "+ readerId).executeUpdate();
|
||||||
|
final Reader currentReader = findReader(readerId);
|
||||||
|
final Manga currentManga = em.find(Manga.class, manga.getId());
|
||||||
|
currentReader.getMangas().remove(currentManga);
|
||||||
|
currentManga.getReaders().remove(currentReader);
|
||||||
|
em.merge(currentReader);
|
||||||
|
em.merge(currentManga);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
|
@ -240,6 +240,7 @@ public class ReMangaTest {
|
|||||||
Manga m11 = mangaService.findManga(m1.getId());
|
Manga m11 = mangaService.findManga(m1.getId());
|
||||||
Assertions.assertEquals(1, r12.getMangas().size());
|
Assertions.assertEquals(1, r12.getMangas().size());
|
||||||
log.info(mangaService.findAllMangas().toString());
|
log.info(mangaService.findAllMangas().toString());
|
||||||
|
log.info(r12.getMangas().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user