简体   繁体   中英

How to combine different data types java

I have three different entities (Deposit,Withdraw and Transfer). Deposit and Withdraw have the same schema structure(so no need of me showing the entity) but transfer is slightly different. I have a requirement to fetch all user transactions and sort them without the front-end doing extra logic. How do i join them and sort since they are of different structure?

Below is the structure of Deposit:

public class Deposit{    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(nullable = false,updatable = false)
    private Long id;
    @Column(nullable = false,updatable = false)
    private Long sourceAccount;
    @Column(nullable = false,updatable = false)
    @Positive
    private BigDecimal amount;
    @OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(nullable = false,name = "transaction_detail_id")
    private TransactionDetail transactionDetail;
    @CreationTimestamp
    @Column(nullable = false,updatable = false)
    private Date transactionDate;
    @CreationTimestamp
    @Column(nullable = false,updatable = false)
    private Time time;
}

Transfer

public class Transfer {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(nullable = false,updatable = false)
    private Long id;
    @Column(nullable = false,updatable = false)
    private Long sourceAccount;
    @Column(nullable = false,updatable = false,name = "desc_acct")
    private Long recipientAccount;
    @Column(nullable = false,updatable = false)
    private BigDecimal amount;
    @OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(nullable = false,name = "transaction_detail_id")
    private TransactionDetail transactionDetail;
    @CreationTimestamp
    @Column(nullable = false,updatable = false)
    private Date transactionDate;
    @CreationTimestamp
    @Column(nullable = false,updatable = false)
    private Time time;

}

Thanks

You can create a model like DTO (Data Transfer Object), then you get/set value for DTO and sort them before transfer it to front-end.

Another solution is using Bazaarvoice Jolt instead of get/set manually

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM