Hibernate addjoin method: associate an entity with a collection
•
Java
addJoin(String alias,String path)
Example
Session session = sessionFactory.openSession(); //创建Session对象
String sql = "select{order.*},{order_detail.*}from tb_order order,tb_orderDetail
order_detail where order.id=order_detail.orderId"; //定义查询语句
List list = null;
List rtnList = new ArrayList(); //定义保存查询结果集的集合对象
try{
sqlQuery query = session.createsqlQuery(sql); //执行查询语句
query.addEntity("order",Order.class); //绑定查询参数
query.addJoin("order_detail","com.model.OrderDetailForm");
list = query.list();
}catch(Exception e){
System.out.println("查询用户信息时的错误信息:"+e.getMessage());
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
