日期:2014-05-20 浏览次数:20937 次
String sql = "select id, product, model, brand, encap, postil, quantity, " +
"price from t_quotation where inquire_id in (select id from t_inquire " +
"where name = 'fff') ";
SQLQuery sq = this.hibernateTemplate.getSessionFactory().getCurrentSession().createSQLQuery(sql);
sq.addEntity(Quotation.class);
sq.list();
public class Quotation {
private Integer id;
private Inquire inquire;
private String product;
private String model;
private String brand;
private String encap;
private String postil;
private Integer quantity;
private Double price;
//get set 略
}
public class Inquire {
private Integer id;
private String name;
//get set 略
}
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.Quotation" table="t_quotation" >
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="increment" />
</id>
<many-to-one name="inquire" column="inquire_id" update="false"
class="com.Inquire" lazy="false"
not-found="ignore">
</many-to-one>
<property name="product" type="java.lang.String">
<column name="product" length="30" />
</property>
<property name="model" type="java.lang.String">
<column name="model" length="20" />
</property>
<property name="brand" type="java.lang.String">
<column name="brand" length="20" />
</property>
<property name="encap" type="java.lang.String">
<column name="encap" length="20" />
</property>
<property name="postil" type="java.lang.String">
<column name="postil" length="20" />
</property>
<property name="quantity" type="java.lang.Integer">
<column name="quantity" />
</property>
<property name="price" type="java.lang.Double">
<column name="price" precision="10" scale="3" />
</property>
</class>
</hibernate-mapping>