Hibernate 本地SQL查询 (二)

2014-11-24 11:10:33 · 作者: · 浏览: 1
private Date date;

private Integer price;

private String contact;

private Integer floorage;

private String title;

public Integer getId() {
return id;
}

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

public Integer getType_id() {
return type_id;
}

public void setType_id(Integer type_id) {
this.type_id = type_id;
}

public Integer getUser_id() {
return user_id;
}

public void setUser_id(Integer user_id) {
this.user_id = user_id;
}

public Integer getStreet_id() {
return street_id;
}

public void setStreet_id(Integer street_id) {
this.street_id = street_id;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public Date getDate() {
return date;
}

public void setDate(Date date) {
this.date = date;
}

public Integer getPrice() {
return price;
}

public void setPrice(Integer price) {
this.price = price;
}

public String getContact() {
return contact;
}

public void setContact(String contact) {
this.contact = contact;
}

public Integer getFloorage() {
return floorage;
}

public void setFloorage(Integer floorage) {
this.floorage = floorage;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

}

5.映射文件

House.hbm.xml


< xml version="1.0" >
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">




































6.映射文件

User.hbm.xml

< xml version="1.0" >
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">






SEQ_ID
























select {u.*},{h.*} from users u,house h where u.id=h.user_id
]]>




测试类


Test.java

import java.util.Iterator;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import cn.jbit.hibernate.entity.House;
import cn.jbit.hibernate.entity.QueryProperties;
import cn.jbit.hibernate.entity.User;
import cn.jbit.hibernate.util.HibernateUtil;


public class Test {


public static void main(String[] args) {
HibernateUtil u= new HibernateUtil();
SessionFactory sf = null;
Session session =null;
Transaction tx=null;
try{
session=u.getSession();