我有一个名为MachineSalesReport的类:
@Entity
@Table(name = "machine_report")
public class MachineSalesReport implements Serializable, Cloneable {
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column
private int id;
@Column(name = "avery_sales_order_no")
private String averySalesOrderNo;
@Column(name = "editor")
private String editor;
@Column(name = "edit_date")
private Date editDate;
@Column(name = "ship_out_date")
private Date shipOutDate;
@Column(name = "remarks")
private String remarks;
@Column(name = "nature_of_sales")
private String natureOfSales;
@Column(name = "supply_agreement")
private String supplyagreement;
@Column(name = "retailer")
private String retailer;
@Column(name = "program")
private String program;
@Column(name = "product_line")
private String productLine;
@Column(name = "is_final")
private String isFinal;
@Column(name = "exists")
private String exists;
@Column(name = "contract_flag")
private boolean contractFlag;
@Column(name = "installation_flag")
private boolean installationFlag;
@Column(name = "last_update_date")
private Timestamp lastUpdateTime;
@Column(name = " last_update_editor")
private String lastUpdateEditor;
@Column(name = "email_flag")
private boolean emailFlag;
@OneToOne(cascade = CascadeType.ALL,fetch = FetchType.LAZY)
@JoinColumn(name = "internal_information_id")
private InternalInformation internalInformation;
@OneToOne(cascade = CascadeType.ALL,fetch = FetchType.LAZY)
@JoinColumn(name = "customer_information_id")
private CustomerInformation customerInformation;
@OneToOne(cascade = CascadeType.ALL,fetch = FetchType.LAZY)
@JoinColumn(name = "installation_information_id")
private InstallationInformation installationInformation;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "machineSalesReport")
private List<ContractsAndWarranty> contracts;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getAverySalesOrderNo() {
return averySalesOrderNo;
}
public void setAverySalesOrderNo(String averySalesOrderNo) {
this.averySalesOrderNo = averySalesOrderNo;
}
public String getEditor() {
return editor;
}
public void setEditor(String editor) {
this.editor = editor;
}
public Date getEditDate() {
return editDate;
}
public void setEditDate(Date editDate) {
this.editDate = editDate;
}
public Date getShipOutDate() {
return shipOutDate;
}
public void setShipOutDate(Date shipOutDate) {
this.shipOutDate = shipOutDate;
}
public String getRemarks() {
return remarks;
}
public void setRemarks(String remarks) {
this.remarks = remarks;
}
public String getNatureOfSales() {
return natureOfSales;
}
public boolean isEmailFlag() {
return emailFlag;
}
public void setEmailFlag(boolean emailFlag) {
this.emailFlag = emailFlag;
}
public void setNatureOfSales(String natureOfSales) {
this.natureOfSales = natureOfSales;
}
public String getRetailer() {
return retailer;
}
public void setRetailer(String retailer) {
this.retailer = retailer;
}
public String getProgram() {
return program;
}
public void setProgram(String program) {
this.program = program;
}
public String getProductLine() {
return productLine;
}
public void setProductLine(String productLine) {
this.productLine = productLine;
}
public InternalInformation getInternalInformation() {
return internalInformation;
}
public void setInternalInformation(InternalInformation internalInformation) {
this.internalInformation = internalInformation;
}
public CustomerInformation getCustomerInformation() {
return customerInformation;
}
public void setCustomerInformation(CustomerInformation customerInformation) {
this.customerInformation = customerInformation;
}
public InstallationInformation getInstallationInformation() {
return installationInformation;
}
public void setInstallationInformation(
InstallationInformation installationInformation) {
this.installationInformation = installationInformation;
}
public String getIsFinal() {
return isFinal;
}
public void setIsFinal(String isFinal) {
this.isFinal = isFinal;
}
public String getExists() {
return exists;
}
public void setExists(String exists) {
this.exists = exists;
}
public boolean isContractFlag() {
return contractFlag;
}
public void setContractFlag(boolean contractFlag) {
this.contractFlag = contractFlag;
}
public boolean isInstallationFlag() {
return installationFlag;
}
public void setInstallationFlag(boolean installationFlag) {
this.installationFlag = installationFlag;
}
public List<ContractsAndWarranty> getContracts() {
return contracts;
}
public void setContracts(List<ContractsAndWarranty> contracts) {
this.contracts = contracts;
}
public Date getLastUpdateTime() {
return lastUpdateTime;
}
public String getLastUpdateEditor() {
return lastUpdateEditor;
}
public void setLastUpdateTime(Timestamp lastUpdateTime) {
this.lastUpdateTime = lastUpdateTime;
}
public void setLastUpdateEditor(String lastUpdateEditor) {
this.lastUpdateEditor = lastUpdateEditor;
}
public String getSupplyagreement() {
return supplyagreement;
}
public void setSupplyagreement(String supplyagreement) {
this.supplyagreement = supplyagreement;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime
* result
+ ((averySalesOrderNo == null) ? 0 : averySalesOrderNo
.hashCode());
result = prime * result + (contractFlag ? 1231 : 1237);
result = prime * result
+ ((contracts == null) ? 0 : contracts.hashCode());
result = prime
* result
+ ((customerInformation == null) ? 0 : customerInformation
.hashCode());
result = prime * result
+ ((editDate == null) ? 0 : editDate.hashCode());
result = prime * result + ((editor == null) ? 0 : editor.hashCode());
result = prime * result + ((exists == null) ? 0 : exists.hashCode());
result = prime * result + id;
result = prime * result + (installationFlag ? 1231 : 1237);
result = prime
* result
+ ((installationInformation == null) ? 0
: installationInformation.hashCode());
result = prime
* result
+ ((internalInformation == null) ? 0 : internalInformation
.hashCode());
result = prime * result + ((isFinal == null) ? 0 : isFinal.hashCode());
result = prime * result
+ ((natureOfSales == null) ? 0 : natureOfSales.hashCode());
result = prime * result
+ ((productLine == null) ? 0 : productLine.hashCode());
result = prime * result + ((program == null) ? 0 : program.hashCode());
result = prime * result + ((remarks == null) ? 0 : remarks.hashCode());
result = prime * result
+ ((retailer == null) ? 0 : retailer.hashCode());
result = prime * result
+ ((shipOutDate == null) ? 0 : shipOutDate.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
MachineSalesReport other = (MachineSalesReport) obj;
if (averySalesOrderNo == null) {
if (other.averySalesOrderNo != null)
return false;
} else if (!averySalesOrderNo.equals(other.averySalesOrderNo))
return false;
if (contractFlag != other.contractFlag)
return false;
if (contracts == null) {
if (other.contracts != null)
return false;
} else if (!contracts.equals(other.contracts))
return false;
if (customerInformation == null) {
if (other.customerInformation != null)
return false;
} else if (!customerInformation.equals(other.customerInformation))
return false;
if (editDate == null) {
if (other.editDate != null)
return false;
} else if (!editDate.equals(other.editDate))
return false;
if (editor == null) {
if (other.editor != null)
return false;
} else if (!editor.equals(other.editor))
return false;
if (exists == null) {
if (other.exists != null)
return false;
} else if (!exists.equals(other.exists))
return false;
if (id != other.id)
return false;
if (installationFlag != other.installationFlag)
return false;
if (installationInformation == null) {
if (other.installationInformation != null)
return false;
} else if (!installationInformation
.equals(other.installationInformation))
return false;
if (internalInformation == null) {
if (other.internalInformation != null)
return false;
} else if (!internalInformation.equals(other.internalInformation))
return false;
if (isFinal == null) {
if (other.isFinal != null)
return false;
} else if (!isFinal.equals(other.isFinal))
return false;
if (natureOfSales == null) {
if (other.natureOfSales != null)
return false;
} else if (!natureOfSales.equals(other.natureOfSales))
return false;
if (productLine == null) {
if (other.productLine != null)
return false;
} else if (!productLine.equals(other.productLine))
return false;
if (program == null) {
if (other.program != null)
return false;
} else if (!program.equals(other.program))
return false;
if (remarks == null) {
if (other.remarks != null)
return false;
} else if (!remarks.equals(other.remarks))
return false;
if (retailer == null) {
if (other.retailer != null)
return false;
} else if (!retailer.equals(other.retailer))
return false;
if (shipOutDate == null) {
if (other.shipOutDate != null)
return false;
} else if (!shipOutDate.equals(other.shipOutDate))
return false;
return true;
}
@Override
public String toString() {
return "MachineSalesReport [id=" + id + ", averySalesOrderNo="
+ averySalesOrderNo + ", editor=" + editor + ", editDate="
+ editDate + ", shipOutDate=" + shipOutDate + ", remarks="
+ remarks + ", natureOfSales=" + natureOfSales + ", retailer="
+ retailer + ", program=" + program + ", productLine="
+ productLine + ", isFinal=" + isFinal + ", exists=" + exists
+ ", contractFlag=" + contractFlag + ", installationFlag="
+ installationFlag + ", internalInformation="
+ internalInformation + ", customerInformation="
+ customerInformation + ", installationInformation="
+ installationInformation + ", contracts=" + contracts + "]";
}
@Override
public Object clone() {
MachineSalesReport report = null;
try {
report = (MachineSalesReport) super.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
List<ContractsAndWarranty> contracts = new ArrayList<ContractsAndWarranty>();
for (int i = 0; i < this.contracts.size(); i++) {
ContractsAndWarranty contract = (ContractsAndWarranty) this.contracts
.get(i).clone();
contracts.add(contract);
}
report.setContracts(contracts);
return report;
}
}
我有一个Dao是:System.out.println("*************begin**");
Criteria dc = sessionFactory.getCurrentSession().createCriteria(MachineSalesReport.class,"mr")
.createAlias("mr.installationInformation", "install").createAlias("mr.customerInformation","customer").createAlias("mr.internalInformation", "internal");
dc.setMaxResults(1);
List<MachineSalesReport> reports= dc.list();
System.out.println("*************end**");
并运行dao,我的控件显示sql有3个sql:
Hibernate: select this_.id as id5_6_, this_.avery_sales_order_no as avery2_5_6_, this_.contract_flag as contract3_5_6_, this_.customer_information_id as customer19_5_6_, this_.edit_date as edit4_5_6_, this_.editor as editor5_6_, this_.email_flag as email6_5_6_, this_.exists as exists5_6_, this_.installation_flag as installa8_5_6_, this_.installation_information_id as install20_5_6_, this_.internal_information_id as internal21_5_6_, this_.is_final as is9_5_6_, this_. last_update_editor as column10_5_6_, this_.last_update_date as last11_5_6_, this_.nature_of_sales as nature12_5_6_, this_.product_line as product13_5_6_, this_.program as program5_6_, this_.remarks as remarks5_6_, this_.retailer as retailer5_6_, this_.ship_out_date as ship17_5_6_, this_.supply_agreement as supply18_5_6_, customer2_.id as id1_0_, customer2_.bill_to_company_address_cn as bill2_1_0_, customer2_.bill_to_company_address_en as bill3_1_0_, customer2_.bill_to_company_name as bill4_1_0_, customer2_.bill_to_code as bill5_1_0_, customer2_.bill_to_country as bill6_1_0_, customer2_.customer_email as customer7_1_0_, customer2_.customer_fax as customer8_1_0_, customer2_.customer_phone as customer9_1_0_, customer2_.customer_name as customer10_1_0_, customer2_.ship_from as ship11_1_0_, customer2_.ship_to_company_address_cn as ship12_1_0_, customer2_.ship_to_company_address_en as ship13_1_0_, customer2_.ship_to_company_name as ship14_1_0_, machinesal6_.id as id5_1_, machinesal6_.avery_sales_order_no as avery2_5_1_, machinesal6_.contract_flag as contract3_5_1_, machinesal6_.customer_information_id as customer19_5_1_, machinesal6_.edit_date as edit4_5_1_, machinesal6_.editor as editor5_1_, machinesal6_.email_flag as email6_5_1_, machinesal6_.exists as exists5_1_, machinesal6_.installation_flag as installa8_5_1_, machinesal6_.installation_information_id as install20_5_1_, machinesal6_.internal_information_id as internal21_5_1_, machinesal6_.is_final as is9_5_1_, machinesal6_. last_update_editor as column10_5_1_, machinesal6_.last_update_date as last11_5_1_, machinesal6_.nature_of_sales as nature12_5_1_, machinesal6_.product_line as product13_5_1_, machinesal6_.program as program5_1_, machinesal6_.remarks as remarks5_1_, machinesal6_.retailer as retailer5_1_, machinesal6_.ship_out_date as ship17_5_1_, machinesal6_.supply_agreement as supply18_5_1_, install1_.id as id2_2_, install1_.customer_email as customer2_2_2_, install1_.customer_fax as customer3_2_2_, install1_.customer_name as customer4_2_2_, install1_.customer_phone as customer5_2_2_, install1_.factory_address_cn as factory6_2_2_, install1_.factory_address_en as factory7_2_2_, install1_.factory_name as factory8_2_2_, machinesal8_.id as id5_3_, machinesal8_.avery_sales_order_no as avery2_5_3_, machinesal8_.contract_flag as contract3_5_3_, machinesal8_.customer_information_id as customer19_5_3_, machinesal8_.edit_date as edit4_5_3_, machinesal8_.editor as editor5_3_, machinesal8_.email_flag as email6_5_3_, machinesal8_.exists as exists5_3_, machinesal8_.installation_flag as installa8_5_3_, machinesal8_.installation_information_id as install20_5_3_, machinesal8_.internal_information_id as internal21_5_3_, machinesal8_.is_final as is9_5_3_, machinesal8_. last_update_editor as column10_5_3_, machinesal8_.last_update_date as last11_5_3_, machinesal8_.nature_of_sales as nature12_5_3_, machinesal8_.product_line as product13_5_3_, machinesal8_.program as program5_3_, machinesal8_.remarks as remarks5_3_, machinesal8_.retailer as retailer5_3_, machinesal8_.ship_out_date as ship17_5_3_, machinesal8_.supply_agreement as supply18_5_3_, internal3_.id as id3_4_, internal3_.avery_entity_name as avery2_3_4_, internal3_.city as city3_4_, internal3_.country as country3_4_, internal3_.csr_email as csr5_3_4_, internal3_.csr_name as csr6_3_4_, internal3_.csr_phone as csr7_3_4_, internal3_.salesperson_email as salesper8_3_4_, internal3_.salesperson_name as salesper9_3_4_, internal3_.salesperson_phone as salespe10_3_4_, machinesal10_.id as id5_5_, machinesal10_.avery_sales_order_no as avery2_5_5_, machinesal10_.contract_flag as contract3_5_5_, machinesal10_.customer_information_id as customer19_5_5_, machinesal10_.edit_date as edit4_5_5_, machinesal10_.editor as editor5_5_, machinesal10_.email_flag as email6_5_5_, machinesal10_.exists as exists5_5_, machinesal10_.installation_flag as installa8_5_5_, machinesal10_.installation_information_id as install20_5_5_, machinesal10_.internal_information_id as internal21_5_5_, machinesal10_.is_final as is9_5_5_, machinesal10_. last_update_editor as column10_5_5_, machinesal10_.last_update_date as last11_5_5_, machinesal10_.nature_of_sales as nature12_5_5_, machinesal10_.product_line as product13_5_5_, machinesal10_.program as program5_5_, machinesal10_.remarks as remarks5_5_, machinesal10_.retailer as retailer5_5_, machinesal10_.ship_out_date as ship17_5_5_, machinesal10_.supply_agreement as supply18_5_5_ from machine_report this_ inner join customer_information customer2_ on this_.customer_information_id=customer2_.id left outer join machine_report machinesal6_ on customer2_.id=machinesal6_.customer_information_id inner join installation_information install1_ on this_.installation_information_id=install1_.id left outer join machine_report machinesal8_ on install1_.id=machinesal8_.installation_information_id inner join internal_information internal3_ on this_.internal_information_id=internal3_.id left outer join machine_report machinesal10_ on internal3_.id=machinesal10_.internal_information_id limit ?
Hibernate: select machinesal0_.id as id5_0_, machinesal0_.avery_sales_order_no as avery2_5_0_, machinesal0_.contract_flag as contract3_5_0_, machinesal0_.customer_information_id as customer19_5_0_, machinesal0_.edit_date as edit4_5_0_, machinesal0_.editor as editor5_0_, machinesal0_.email_flag as email6_5_0_, machinesal0_.exists as exists5_0_, machinesal0_.installation_flag as installa8_5_0_, machinesal0_.installation_information_id as install20_5_0_, machinesal0_.internal_information_id as internal21_5_0_, machinesal0_.is_final as is9_5_0_, machinesal0_. last_update_editor as column10_5_0_, machinesal0_.last_update_date as last11_5_0_, machinesal0_.nature_of_sales as nature12_5_0_, machinesal0_.product_line as product13_5_0_, machinesal0_.program as program5_0_, machinesal0_.remarks as remarks5_0_, machinesal0_.retailer as retailer5_0_, machinesal0_.ship_out_date as ship17_5_0_, machinesal0_.supply_agreement as supply18_5_0_ from machine_report machinesal0_ where machinesal0_.installation_information_id=?
Hibernate: select machinesal0_.id as id5_0_, machinesal0_.avery_sales_order_no as avery2_5_0_, machinesal0_.contract_flag as contract3_5_0_, machinesal0_.customer_information_id as customer19_5_0_, machinesal0_.edit_date as edit4_5_0_, machinesal0_.editor as editor5_0_, machinesal0_.email_flag as email6_5_0_, machinesal0_.exists as exists5_0_, machinesal0_.installation_flag as installa8_5_0_, machinesal0_.installation_information_id as install20_5_0_, machinesal0_.internal_information_id as internal21_5_0_, machinesal0_.is_final as is9_5_0_, machinesal0_. last_update_editor as column10_5_0_, machinesal0_.last_update_date as last11_5_0_, machinesal0_.nature_of_sales as nature12_5_0_, machinesal0_.product_line as product13_5_0_, machinesal0_.program as program5_0_, machinesal0_.remarks as remarks5_0_, machinesal0_.retailer as retailer5_0_, machinesal0_.ship_out_date as ship17_5_0_, machinesal0_.supply_agreement as supply18_5_0_ from machine_report machinesal0_ where machinesal0_.internal_information_id=?
为什么sql这么多?我想要第一个sql,并获取MachineSalesReport,包括customerInformation和InternalInformation以及InstallInformation