0

tbl_user_content table am storing the country id. in my response i have show the country name from the tbl_country table,

  1. 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;

}

  1. 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

while debug I can find the country entity have the value

but response entity unable set the value

3
  • I am not seeing any relationship between your entities. Your ContentManage only has a reference to the entity Country but they don;t actually hold any relationship other than you tagging it with JoinColumn. Commented Mar 4, 2021 at 11:08
  • when I used the @query parameter (inner join script) am getting this error"stack_trace":"java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast Commented Mar 5, 2021 at 2:40
  • refer the below: stackoverflow.com/questions/66490776/… Commented Mar 22, 2021 at 7:16

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.