例子
House
package cn
import java
public class House implements java
private Integer id;
private User user;
private Type type;
private Street street;
private String title;
private String description;
private Double price;
private Date date;
private Integer floorage;
private String contact;
public Integer getId() {
return this
}
public void setId(Integer id) {
this
}
public User getUser() {
return this
}
public void setUser(User user) {
this
}
public Type getType() {
return this
}
public void setType(Type type) {
this
}
public Street getStreet() {
return this
}
public void setStreet(Street street) {
this
}
public String getTitle() {
return this
}
public void setTitle(String title) {
this
}
public String getDescription() {
return this
}
public void setDescription(String description) {
this
}
public Double getPrice() {
return this
}
public void setPrice(Double price) {
this
}
public Date getDate() {
return this
}
public void setDate(Date date) {
this
}
public Integer getFloorage() {
return this
}
public void setFloorage(Integer floorage) {
this
}
public String getContact() {
return ntact;
}
public void setContact(String contact) {
ntact = contact;
}
}
House
<?xml version=
<!DOCTYPE hibernate
<!
Mapping file autogenerated by MyEclipse Persistence Tools
<hibernate
<class name=
<id name=
<column name=
<generator class=
<param name=
</generator>
</id>
<many
<column name=
</many
<many
<column name=
</many
<many
<column name=
</many
<property name=
<column name=
</property>
<property name=
<column name=
</property>
<property name=
<column name=
</property>
<property name=
<column name=
</property>
<property name=
<column name=
</property>
<property name=
<column name=
</property>
</class>
<
<query name=
<![CDATA[
from House where (title like :title) and
(price between :low_price and :high_price) and
(street_id like :street_id) and (type_id like :type_id) and
(floorage between :small_floorage and :big_floorage)
]]>
</query>
</hibernate
QueryProperties
package cn
import java
public class QueryProperties {
private String title;
private Double high_price;
private Double low_price;
private Date start_date;
private Date end_date;
private String type_id;
private String street_id;
private Integer small_floorage;
private Integer big_floorage;
public Double getHigh_price() {
return high_price;
}
public void setHigh_price(Double high_price) {
this
}
public Double getLow_price() {
return low_price;
}
public void setLow_price(Double low_price) {
this
}
public String getType_id() {
return type_id;
}
public void setType_id(String type_id) {
this
}
public String getStreet_id() {
return street_id;
}
public void setStreet_id(String street_id) {
this
}
public Date getStart_date() {
return start_date;
}
public void setStart_date(Date start_date) {
this
}
public Date getEnd_date() {
return end_date;
}
public void setEnd_date(Date end_date) {
this
}
public Integer getSmall_floorage() {
return small_floorage;
}
public void setSmall_floorage(Integer small_floorage) {
this
}
public Integer getBig_floorage() {
return big_floorage;
}
public void setBig_floorage(Integer big_floorage) {
this
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this
}
}
Test
import java
import java
import org
import org
import org
import org
import org
import cn
import cn
import cn
import cn
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
HibernateUtil u= new HibernateUtil();
SessionFactory sf = null;
Session session =null;
Transaction tx=null;
try{
session=u
tx=session
Query query =session
//給封裝參數類添加參數值
QueryProperties qp = new QueryProperties();
qp
qp
qp
qp
qp
qp
qp
query
List result =query
Iterator it = erator();
if(it
House house=(House)it
System
}*/
//String hql =
String hql=
Query query = session
List list=query
}catch(HibernateException e){
e
}
}
}
注意
From:http://tw.wingwit.com/Article/program/Java/ky/201311/28724.html