Good day! There is a problem, I use the Jackson library to work with JSON, when I get a list of objects, I get some of them filled up not completely, i.e. from the entity, only the id field is taken, and the rest are ignored. Those. the other fields are not null, they simply do not serialize.

@Entity @Table(name = "dolgnost", schema = "") @XmlRootElement @EntityListeners(DefaultListener.class) public class Dolgnost implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Basic(optional = false) @Column(name = "iddolgnost", nullable = false) private Integer iddolgnost; @Basic(optional = false) @Column(name = "naim_dolgnost", nullable = false, length = 45) private String naimDolgnost; @Column(name = "vus", length = 20) private String vus; @Basic(optional = false) @Column(name = "nomer_pp", nullable = false) private int nomerPp; @JoinColumn(name = "id_zvanie_cat", referencedColumnName = "idzvanie_cat") @ManyToOne (fetch = FetchType.LAZY) private ZvanieCat idZvanieCat; 

And the nested object:

 @Entity @Table(name = "zvanie_cat", schema = "") @XmlRootElement @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "idzvanieCat", scope = ZvanieCat.class) public class ZvanieCat implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Basic(optional = false) @Column(name = "idzvanie_cat", nullable = false) private Integer idzvanieCat; @Basic(optional = false) @Column(name = "naim_zvanie", nullable = false, length = 50) private String naimZvanie; @Column(name = "kateg_vsl", length = 45) private String kategVsl; @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "idZvanieCat") @JsonIgnore private Set<PensionRazmer> pensionRazmerSet; @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "idzvanieCat") private Set<ZvaniePoluch> zvaniePoluchSet; @OneToMany(fetch = FetchType.EAGER, mappedBy = "idZvanieCat") @JsonIgnore private Set<Dolgnost> dolgnostSet; @JoinColumn(name = "id_poluch_cat", referencedColumnName = "idpoluch_cat", nullable = false) @ManyToOne(fetch = FetchType.EAGER, optional = false) private PoluchCat poluchCat; @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "idZvanieCat") @JsonIgnore private Set<ZvanieRazmer> zvanieRazmerSet; 

So, the zvanieCat object in the dolgnost object does not come in full, but only in the form of id.

  • It seems to me that this is related to fetch = FetchType.LAZY . In general, using one class for ORM and for giving out is a bad idea. - Nofate
  • How about looking in the direction of Gson? - Danil
  • The problem was in the annotation '@JsonIdentityInfo', I apologize. - Artificial_A

0