hibernate多表查询返回的集合映射成自定义对象

1、DAO

public class ParamDao extends FoHibernateDaoSupport implements IParamDao  {    
        @Override
    	public List<AgentMaxUserEntity> queryMaxUser() {
        String sql = "select d.aaa as aaa,d.bbb as bbb,d.ccc as ccc, "
                + " c.description as ddd,c.paramkey as eee" 
                + " from "
                + " (select a.aaa,a.bbb,b.ccc "
                + " from table_a a,table_b b "
                + " where a.aaa = b.fff) d "
                + " left join table_c c "
                + " on d.aaa = c.aaa ";
        FoSQLQuery query = new FoSQLQuery(sql);
        query.addEntity("test", TestEntity.class);
        return this.execFoQuery(query);
    }

2、Entity 定义返回的对象,set get都要写

public class TestEntity {
    private String aaa;
    private String bbb;
    private String ccc;
    private String ddd;
    private String eee;  

3、Hibernate映射

<?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 package="com.test.cc.entity">
    <class name="TestEntity" >   //不需要映射table
        <id name="aaa" type="java.lang.String">
             <generator class="assigned"/>
        </id>
        <property name="bbb" type="java.lang.String" length="32"/>   //不需要映射column
        <property name="ccc" type="java.lang.String" length="32"/>  
        <property name="ddd" type="java.lang.String" length="64"/>  
        <property name="eee" type="java.lang.String" length="64"/>  
    </class>
</hibernate-mapping>










评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值