Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java HQL如何对实体中的列表使用sum函数_Java_Hibernate_Hql - Fatal编程技术网

Java HQL如何对实体中的列表使用sum函数

Java HQL如何对实体中的列表使用sum函数,java,hibernate,hql,Java,Hibernate,Hql,大家好,我需要你们的帮助 如何将HQL的Sum函数用于一个实体的列表 我试图通过代码示例来解释我的问题 这是我的发票 @Entity public class Invoice extends ExtendedBaseEntity { @Column(nullable = true,length = 50) private String invoiceNo; @Column(nullable = true) @JsonFormat(shape = JsonFormat.Shape.STRING

大家好,我需要你们的帮助

如何将HQL的Sum函数用于一个实体的列表

我试图通过代码示例来解释我的问题

这是我的发票

@Entity
public class Invoice extends ExtendedBaseEntity {

@Column(nullable = true,length = 50)
private String invoiceNo;

@Column(nullable = true)
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX", timezone = "EET")
private Date invoiceDate;

@Column(nullable = true,precision = 10,scale = 2)
private BigDecimal amount; getters and setters.....
这是我的文件实体。这个实体有一个发票列表

@Entity    
public class File extends ExtendedBaseEntity {
@Column(nullable = true, length = 50)
private String name;

@Column(nullable = true, length = 50)
private String surname;

@Column(nullable = true, length = 50)
private String lawyerCode;

@Column(nullable = true, length = 50)
private String sellerCode;

@OneToMany(cascade = CascadeType.REMOVE, fetch = FetchType.EAGER)
@Fetch(FetchMode.SELECT)
@JoinColumn(name = "MBSFILE_OID")
private List<Invoice> invoices = new ArrayList<Invoice>(); setters and getters ....

我该如何应对?你能帮我吗?

好的,你需要一份
groupby
声明好的,非常感谢我处理了。好的,你需要一份
groupby
声明好的,非常感谢我处理了。
SELECT DISTINCT
            SUM(invoice.amount) AS totalAmount
FROM file 
LEFT JOIN file.invoices AS invoice