为什么在实体中使用 JPA 列出(@OneToMany)看到 PersistentBag

Why List(@OneToMany) with JPA in Entity seen PersistentBag

我有两个实体 Personel.java 和 PersonelEgitimDurum.java List personelEgitimDurumList is PersistentBag in Personel 如下所示;

[enter image description here][1] 


  [1]: https://i.stack.imgur.com/Q3IC2.png

Personel.java如下;

    @Entity
@Table(name="personel")
public class Personel extends BaseEntity {

    @OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(name="kisi_id")
    private Kisi kisi;

    @Column(name="personel_tipi",length = 2,nullable = false)
    private int personelTipi;

    @Column(name="sicil_no",length = 100,nullable = false)
    private String sicilNo;

    @OneToMany(fetch = FetchType.EAGER, mappedBy = "personel", cascade =CascadeType.ALL,orphanRemoval = true)
    private List<PersonelEgitimDurum> personelEgitimDurumList= new ArrayList<PersonelEgitimDurum>();

    @Column(name="khk_onay",length = 1)
    private int khkOnay;
}

PersonelEgitimDurum.java如下;

    @Entity
@Table(name = "personel_egitim_durum", indexes = {@Index(name = "index_personel_egitim_durum", columnList = "id")})
public class PersonelEgitimDurum extends BaseEntity {

    @ManyToOne(cascade=CascadeType.PERSIST,fetch=FetchType.EAGER)
    @JoinColumn(name="personel_id",nullable = false, updatable = true)
    private Personel personel;

    @Column(name = "ogrenim_durumu")
    private String ogrenimDurumu;

    @Column(name = "okul_id", length = 3)
    private Long okulId;

    @Column(name = "universite_bolum_id", length = 4)
    private Long universiteBolumId;

    @Column(name = "mezuniyet_tarihi")
    private Date mezuniyetTarihi;

    @Column(name = "aciklama", length = 500)
    private String aciklama;
}

PersonelServiceImpl.java如下;

@Service
@Transactional
public class PersonelServiceImpl implements PersonelService {
@Override
    public PersonelDTO findPersonelByKimlikNo(String kimlikNo) {
        Kisi kisi=kisiDAO.findKisiByKimlikNo(kimlikNo);
        Personel personel=personelDao.findPersonelByKisi(kisi);
        PersonelDTO personelDTO=mapper.toDto(personel);
        return personelDTO;
    }
}

问题是来自 PersonelServiceImpl 中的 findPersonelByKimlikNo 的人员包括 personelEgitimDurumList 是 PersistentBag 作为图像 。所以 mapStruct 不会将实体转换为 dto.

错误日志如下;

java.lang.WhosebugError: null
at org.hibernate.collection.internal.PersistentBag.size(PersistentBag.java:261) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
at org.kktcmeb.personel.kktcmebpersonel.mapper.PersonelMapperImpl.personelEgitimDurumListToPersonelEgitimDurumDTOList(PersonelMapperImpl.java:159) ~[classes/:na]
at org.kktcmeb.personel.kktcmebpersonel.mapper.PersonelMapperImpl.toDto(PersonelMapperImpl.java:53) ~[classes/:na]
at org.kktcmeb.personel.kktcmebpersonel.mapper.PersonelMapperImpl.personelEgitimDurumToPersonelEgitimDurumDTO(PersonelMapperImpl.java:144) ~[classes/:na]
at org.kktcmeb.personel.kktcmebpersonel.mapper.PersonelMapperImpl.personelEgitimDurumListToPersonelEgitimDurumDTOList(PersonelMapperImpl.java:161) ~[classes/:na]
at org.kktcmeb.personel.kktcmebpersonel.mapper.PersonelMapperImpl.toDto(PersonelMapperImpl.java:53) ~[classes/:na]

有人知道这种情况吗?请帮忙

@Entity
@Table(name="personel")
**@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")**
        public class Personel extends BaseEntity {

            @OneToOne(cascade = CascadeType.ALL)
            @JoinColumn(name="kisi_id")
            private Kisi kisi;

            @Column(name="personel_tipi",length = 2,nullable = false)
            private int personelTipi;

            @Column(name="sicil_no",length = 100,nullable = false)
            private String sicilNo;

            @OneToMany(fetch = FetchType.EAGER, mappedBy = "personel", cascade =CascadeType.ALL,orphanRemoval = true)
            private List<PersonelEgitimDurum> personelEgitimDurumList= new ArrayList<PersonelEgitimDurum>();

            @Column(name="khk_onay",length = 1)
            private int khkOnay;
        }

添加到实体的头部->@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, 属性="id")

@Entity
@Table(name = "personel_egitim_durum", indexes = {@Index(name = "index_personel_egitim_durum", columnList = "id")})
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
    public class PersonelEgitimDurum extends BaseEntity {

        @ManyToOne(cascade=CascadeType.PERSIST,fetch=FetchType.EAGER)
        @JoinColumn(name="personel_id",nullable = false, updatable = true)
        private Personel personel;

        @Column(name = "ogrenim_durumu")
        private String ogrenimDurumu;

        @Column(name = "okul_id", length = 3)
        private Long okulId;

        @Column(name = "universite_bolum_id", length = 4)
        private Long universiteBolumId;

        @Column(name = "mezuniyet_tarihi")
        private Date mezuniyetTarihi;

        @Column(name = "aciklama", length = 500)
        private String aciklama;
    }