tbl_user_content table am storing the country id. in my response i have show the country name from the tbl_country table,
- Entity-> A
@Setter
@Getter
@Entity
@AllArgsConstructor
@NoArgsConstructor
@Builder
@DynamicInsert
@Table(name = "tbl_user_content")
public class ContentManage implements Serializable {
private static final long serialVersionUID = -2526575458651174224L;
@Id
@GeneratedValue(strategy= GenerationType.SEQUENCE, generator = "user_content_generator")
@SequenceGenerator(name= "user_content_generator", sequenceName = "tbl_user_content_id_seq", allocationSize = 1)
@Column(name ="id")
private int id;
@Column(name = "position")
private int position;
@Column(name = "title")
private String title;
@Column(name = "shortdescription")
private String shortdescription;
@Column(name = "thumbnailimage")
private String thumbnailimage;
@Column(name = "linkactions")
private String linkactions;
@Column(name = "last_updated_date")
private ZonedDateTime last_updated_date;
@Column(name = "last_updated_by")
private String last_updated_by;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "countryid", insertable = false, updatable = false)
@Fetch(FetchMode.JOIN)
private Country country;
}
- Entity -> B
@Setter
@Getter
@Entity
@AllArgsConstructor
@NoArgsConstructor
@Builder
@DynamicInsert
@Table(name = "tbl_country")
public class Country implements Serializable {
private static final long serialVersionUID = -2526575458651174224L;
@Id
@Column(name ="id")
private String countryId;
@Column(name = "created_dt")
private ZonedDateTime created_date;
@Column(name = "name")
private String countryName;
@OneToMany(targetEntity = ContentManage.class, mappedBy = "country", orphanRemoval = false, fetch = FetchType.EAGER)
private Set<ContentManage> contentManage;
}
Service class
public ContentManageVO queryContenetManage(int contentmanageId) {
System.out.println("contentmanageid value==="+contentmanageId);
Optional<ContentManage> contentManageOptional = contentManageRepository.findById(contentmanageId);
ContentManage contentManage = contentManageOptional
.orElseThrow(() -> new GenericBadException(StaffNotificationExceptionEnum.CONTENT_MANAGE_NOT_FOUND_EXCEPTION));
ContentManageVO contentManageVO = new ContentManageVO();
BeanUtils.copyProperties(contentManage, contentManageVO);
return contentManageVO;
}
API response : country id returns null
{
"id": 17,
"position": 123,
"title": "title",
"shortDescription": "shortdescription",
"thumbnailimage": "thumbnailimage",
"linkactions": "linkactions",
"last_updated_date": "2021-02-23T14:02:42.891+08",
"last_updated_by": "last_updated_by",
"countryid": null
}
please any one suggest