How to combine results from two table with same columns and return the result in Page

For example I've two tables Order1 and Order2 . Now I want to create one GET API name wih /getCombinedOrders which will return the result from Order1 and Order2 in page format.
@Entity
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Order1 {
@Id
@GeneratedValue(strategy = GenerationType.UUID)
private String id;

@Column(name = "QUANTITY")
private String quantity;

@Column(name = "PRODUCT_NAME")
private String productName;

@Column(name = "ORDER_DATE")
private Instant orderDate;

@Column(name = "STATUS")
private String orderStatus;

@Column(name = "TOTAL_AMOUNT")
private long amount;
}

@Entity
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Order2 {
@Id
@GeneratedValue(strategy = GenerationType.UUID)
private String id;

@Column(name = "QUANTITY")
private String quantity;

@Column(name = "PRODUCT_NAME")
private String productName;

@Column(name = "ORDER_DATE")
private Instant orderDate;

@Column(name = "STATUS")
private String orderStatus;

@Column(name = "TOTAL_AMOUNT")
private long amount;
}
@Entity
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Order1 {
@Id
@GeneratedValue(strategy = GenerationType.UUID)
private String id;

@Column(name = "QUANTITY")
private String quantity;

@Column(name = "PRODUCT_NAME")
private String productName;

@Column(name = "ORDER_DATE")
private Instant orderDate;

@Column(name = "STATUS")
private String orderStatus;

@Column(name = "TOTAL_AMOUNT")
private long amount;
}

@Entity
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Order2 {
@Id
@GeneratedValue(strategy = GenerationType.UUID)
private String id;

@Column(name = "QUANTITY")
private String quantity;

@Column(name = "PRODUCT_NAME")
private String productName;

@Column(name = "ORDER_DATE")
private Instant orderDate;

@Column(name = "STATUS")
private String orderStatus;

@Column(name = "TOTAL_AMOUNT")
private long amount;
}
Strategies I tried: I've tried to get the data from Order1 repository and Order2 repository and return the result in Page. This strategy has some drawbacks regarding the Pagination. In this strategy if user pass pageSize 10 then we need to divide it into half and fetch 5 orders from each table combine and return but these is issue if one table has only 2 order left and another table still have 20 orders then our response will be only 7 orders. 2nd strategy will fetch all the data from both table, create list and sort and return but in this approach we negligent the use of Pagination that we do not need to fetch thousand of record for 10 rows on user screen. Could you please help me on this?
1 Reply
JavaBot
JavaBot9mo ago
This post has been reserved for your question.
Hey @Patel! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here. 💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?