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>