是否可以将 ArrayList 数据映射到 DTO?

时间:2021-01-30 09:50:50

标签: java sql spring spring-boot dto

我尝试将数组列表数据转换为 DTO 模式,但出现类似

的错误 <块引用>

Caused by: org.hibernate.MappingException: 无法确定类型 对于:java.util.List,在表:BillingDetailsDTO,对于列: [org.hibernate.mapping.Column(billingDetailsList)]

查询

@Query("select new BillingDetailsDTO (b.id,b.billingDetails) "
        + "from Billing2 b "
        + "where b.id = :billingId")
List<BillingDetailsDTO> selectBillingDetails(Integer billingId);

DTO 模型

@Entity
public class BillingDetailsDTO {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer billingId;
private List<CustomBillingDetails2> billingDetailsList;

public Integer getBillingId() {
    return billingId;
}

public List<CustomBillingDetails2> getBillingDetails() {
    return billingDetailsList;
}

public BillingDetailsDTO(Integer billingId, List<CustomBillingDetails2> billingDetailsList) {
    super();
    this.billingId = billingId;
    this.billingDetailsList = billingDetailsList;
    }
}

CustomBillingDetails2 类

@Entity
public class CustomBillingDetails2 {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    private Integer createdBy;
    private Calendar createdDate;
    private Integer updatedBy;
    private Calendar updatedDate;
    private Integer active;
    private Double qty;
    private Double rate;
    private Double amount;
    private Double discount;
    private Integer billingId;

    @OneToOne
    @JoinColumn(name = "testId")
    private LabTest1 labTest;

    @OneToOne
    @JoinColumn(name = "subtestId")
    private LabSubTest labSubTest;

    public Integer getBillingId() {
        return billingId;
    }

    public void setBillingId(Integer billingId) {
        this.billingId = billingId;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(Integer createdBy) {
        this.createdBy = createdBy;
    }

    public Calendar getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Calendar createdDate) {
        this.createdDate = createdDate;
    }

    public Integer getUpdatedBy() {
        return updatedBy;
    }

    public void setUpdatedBy(Integer updatedBy) {
        this.updatedBy = updatedBy;
    }

    public Calendar getUpdatedDate() {
        return updatedDate;
    }

    public void setUpdatedDate(Calendar updatedDate) {
        this.updatedDate = updatedDate;
    }

    public Integer getActive() {
        return active;
    }

    public void setActive(Integer active) {
        this.active = active;
    }


    public LabTest1 getLabTest() {
        return labTest;
    }

    public void setLabTest(LabTest1 labTest) {
        this.labTest = labTest;
    }

    public LabSubTest getLabSubTest() {
        return labSubTest;
    }

    public void setLabSubTest(LabSubTest labSubTest) {
        this.labSubTest = labSubTest;
    }

    public Double getQty() {
        return qty;
    }

    public void setQty(Double qty) {
        this.qty = qty;
    }

    public Double getRate() {
        return rate;
    }

    public void setRate(Double rate) {
        this.rate = rate;
    }

    public Double getAmount() {
        return amount;
    }

    public void setAmount(Double amount) {
        this.amount = amount;
    }

    public Double getDiscount() {
        return discount;
    }

    public void setDiscount(Double discount) {
        this.discount = discount;
    }

}

billing2 表模态类

@Entity
@Table(name = "\"tbl_billing\"")

public class Billing2 {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    private Integer createdBy;
    private Calendar createdDate;
    private Integer updatedBy;
    private Calendar updatedDate;
    private Integer active;
    private Double totalAmount;
    private Double totalDiscount;
    private Integer isOnline;
    private String collectedFrom;
    private String resultCollectDateTime;
    private Integer doctorId;

    public Integer getDoctorId() {
        return doctorId;
    }

    public void setDoctorId(Integer doctorId) {
        this.doctorId = doctorId;
    }

    @OneToOne
    @JoinColumn(name = "patientId")
    private Patient patients;

    @OneToMany
    @Where(clause = "active=1")
    @JoinColumn(name = "billingId", nullable = false, unique = true, insertable = false, updatable = false)
    private List<BillingDetails2> billingDetails = new ArrayList<>();


    public Integer getId() {
        return id;
    }


    public List<BillingDetails2> getBillingDetails() {
        return billingDetails;
    }

    public void setBillingDetails(List<BillingDetails2> billingDetails) {
        this.billingDetails = billingDetails;
    }

    public Patient getPatients() {
        return patients;
    }

    public void setPatients(Patient patients) {
        this.patients = patients;
    }

    public Double getTotalAmount() {
        return totalAmount;
    }

    public String getResultCollectDateTime() {
        return resultCollectDateTime;
    }

    public void setResultCollectDateTime(String resultCollectDateTime) {
        this.resultCollectDateTime = resultCollectDateTime;
    }

    public String getCollectedFrom() {
        return collectedFrom;
    }

    public void setCollectedFrom(String collectedFrom) {
        this.collectedFrom = collectedFrom;
    }

    public Integer getIsOnline() {
        return isOnline;
    }

    public void setIsOnline(Integer isOnline) {
        this.isOnline = isOnline;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(Integer createdBy) {
        this.createdBy = createdBy;
    }

    public Calendar getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Calendar createdDate) {
        this.createdDate = createdDate;
    }

    public Integer getUpdatedBy() {
        return updatedBy;
    }

    public void setUpdatedBy(Integer updatedBy) {
        this.updatedBy = updatedBy;
    }

    public Calendar getUpdatedDate() {
        return updatedDate;
    }

    public void setUpdatedDate(Calendar updatedDate) {
        this.updatedDate = updatedDate;
    }

    public Integer getActive() {
        return active;
    }

    public void setActive(Integer active) {
        this.active = active;
    }

    public void setTotalAmount(Double totalAmount) {
        this.totalAmount = totalAmount;
    }

    public Double getTotalDiscount() {
        return totalDiscount;
    }

    public void setTotalDiscount(Double totalDiscount) {
        this.totalDiscount = totalDiscount;
    }
}


BillingDetails 2 entity class

    @Entity
    @Table(name = "\"tbl_billing_details\"")
    public class BillingDetails2 {
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        private Integer id;
        private Integer createdBy;
        private Calendar createdDate;
        private Integer updatedBy;
        private Calendar updatedDate;
        private Integer active;
        private Double qty;
        private Double rate;
        private Double amount;
        private Double discount;
        private Integer billingId;
    
        @OneToOne
        @JoinColumn(name = "testId")
        private LabTest1 labTest;
    
        @OneToOne
        @JoinColumn(name = "subtestId")
        private LabSubTest labSubTest;
    
        public Integer getBillingId() {
            return billingId;
        }
    
        public void setBillingId(Integer billingId) {
            this.billingId = billingId;
        }
    
        public Integer getId() {
            return id;
        }
    
        public void setId(Integer id) {
            this.id = id;
        }
    
        public Integer getCreatedBy() {
            return createdBy;
        }
    
        public void setCreatedBy(Integer createdBy) {
            this.createdBy = createdBy;
        }
    
        public Calendar getCreatedDate() {
            return createdDate;
        }
    
        public void setCreatedDate(Calendar createdDate) {
            this.createdDate = createdDate;
        }
    
        public Integer getUpdatedBy() {
            return updatedBy;
        }
    
        public void setUpdatedBy(Integer updatedBy) {
            this.updatedBy = updatedBy;
        }
    
        public Calendar getUpdatedDate() {
            return updatedDate;
        }
    
        public void setUpdatedDate(Calendar updatedDate) {
            this.updatedDate = updatedDate;
        }
    
        public Integer getActive() {
            return active;
        }
    
        public void setActive(Integer active) {
            this.active = active;
        }
    
    
        public LabTest1 getLabTest() {
            return labTest;
        }
    
        public void setLabTest(LabTest1 labTest) {
            this.labTest = labTest;
        }
    
        public LabSubTest getLabSubTest() {
            return labSubTest;
        }
    
        public void setLabSubTest(LabSubTest labSubTest) {
            this.labSubTest = labSubTest;
        }
    
        public Double getQty() {
            return qty;
        }
    
        public void setQty(Double qty) {
            this.qty = qty;
        }
    
        public Double getRate() {
            return rate;
        }
    
        public void setRate(Double rate) {
            this.rate = rate;
        }
    
        public Double getAmount() {
            return amount;
        }
    
        public void setAmount(Double amount) {
            this.amount = amount;
        }
    
        public Double getDiscount() {
            return discount;
        }
    
        public void setDiscount(Double discount) {
            this.discount = discount;
        }
    
    }

自定义帐单明细2类 与 BillingDetails2 实体类相同

@Entity
public class CustomBillingDetails2 {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    private Integer createdBy;
    private Calendar createdDate;
    private Integer updatedBy;
    private Calendar updatedDate;
    private Integer active;
    private Double qty;
    private Double rate;
    private Double amount;
    private Double discount;
    private Integer billingId;

    @OneToOne
    @JoinColumn(name = "testId")
    private LabTest1 labTest;

    @OneToOne
    @JoinColumn(name = "subtestId")
    private LabSubTest labSubTest;

    public Integer getBillingId() {
        return billingId;
    }

    public void setBillingId(Integer billingId) {
        this.billingId = billingId;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(Integer createdBy) {
        this.createdBy = createdBy;
    }

    public Calendar getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Calendar createdDate) {
        this.createdDate = createdDate;
    }

    public Integer getUpdatedBy() {
        return updatedBy;
    }

    public void setUpdatedBy(Integer updatedBy) {
        this.updatedBy = updatedBy;
    }

    public Calendar getUpdatedDate() {
        return updatedDate;
    }

    public void setUpdatedDate(Calendar updatedDate) {
        this.updatedDate = updatedDate;
    }

    public Integer getActive() {
        return active;
    }

    public void setActive(Integer active) {
        this.active = active;
    }


    public LabTest1 getLabTest() {
        return labTest;
    }

    public void setLabTest(LabTest1 labTest) {
        this.labTest = labTest;
    }

    public LabSubTest getLabSubTest() {
        return labSubTest;
    }

    public void setLabSubTest(LabSubTest labSubTest) {
        this.labSubTest = labSubTest;
    }

    public Double getQty() {
        return qty;
    }

    public void setQty(Double qty) {
        this.qty = qty;
    }

    public Double getRate() {
        return rate;
    }

    public void setRate(Double rate) {
        this.rate = rate;
    }

    public Double getAmount() {
        return amount;
    }

    public void setAmount(Double amount) {
        this.amount = amount;
    }

    public Double getDiscount() {
        return discount;
    }

    public void setDiscount(Double discount) {
        this.discount = discount;
    }

}

0 个答案:

没有答案