Hibernate 原生SQL的使用,类似iBaits方式

Hibernate 原生SQL
<? xml version="1.0" ?>
<! DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"
>
<!--  Generated 2007-3-20 16:44:34 by Hibernate Tools 3.2.0.beta8  -->
< hibernate-mapping >
    
< class  name ="com.mip.biz.defect.domain.TypidefdetailVo" >
        
< id  name ="oid"  type ="java.lang.Long" >
            
< column  name ="OID"  precision ="22"  scale ="0"   />
            
< generator  class ="assigned"   />
        
</ id >
        
< property  name ="devtype"  type ="string" >
            
< column  name ="DEVTYPE"  length ="20"   />
        
</ property >
        
< property  name ="pwlevel"  type ="string" >
            
< column  name ="PWLEVEL"  length ="20"   />
        
</ property >
        
< property  name ="stno"  type ="java.lang.Long" >
            
< column  name ="STNO"  precision ="22"  scale ="0"   />
        
</ property >
        
< property  name ="stname"  type ="string" >
            
< column  name ="STNAME"  length ="50"   />
        
</ property >
        
< property  name ="factory"  type ="string" >
            
< column  name ="FACTORY"  length ="40"   />
        
</ property >
    
        
< property  name ="devstyle"  type ="string" >
            
< column  name ="DEVSTYLE"  length ="40"   />
        
</ property >
        
< property  name ="finddate"  type ="java.util.Date" >
            
< column  name ="FINDDATE"  length ="7"   />
        
</ property >
        
< property  name ="definfo"  type ="string" >
            
< column  name ="DEFINFO"  length ="200"   />
        
</ property >
        
< property  name ="defreason"  type ="string" >
            
< column  name ="DEFREASON"  length ="200"   />
        
</ property >
        
< property  name ="measure"  type ="string" >
            
< column  name ="MEASURE"  length ="200"   />
        
</ property >
        
< property  name ="cleardate"  type ="java.util.Date" >
            
< column  name ="CLEARDATE"  length ="7"   />
        
</ property >
      
    
</ class >
    
<!--  典型设备缺陷报表(紧急+重大+一般,详细情况)  -->
< sql-query  name ="queryTypidefdetailReportQuerySql" >
    
< return  alias ="detail"  class ="com.mip.biz.defect.domain.TypidefdetailVo" >
        
< return-property  name ="oid"  column ="typOID" />
        
< return-property  name ="devtype"  column ="typDEVTYPE" />
        
< return-property  name ="pwlevel"  column ="typPWLEVEL" />
        
< return-property  name ="factory"  column ="typFACTORY" />
        
< return-property  name ="devstyle"  column ="typDEVSTYLE" />
        
< return-property  name ="finddate"  column ="typFINDDATE" />
        
< return-property  name ="definfo"  column ="typDEFINFO" />
        
< return-property  name ="defreason"  column ="typDEFREASON" />                                 
        
< return-property  name ="cleardate"  column ="typCLEARDATE" />                                 
        
< return-property  name ="measure"  column ="typMEASURE" />
        
        
< return-property  name ="stno"  column ="typSTNO" />                                                         
        
< return-property  name ="stname"  column ="typeSTNAME" />         
                
    
</ return >
    
<![CDATA[
    SELECT 
        1 as typSTNO,
        'stname' as typeSTNAME,
        definfo.taskbillid AS typOID,
        definfo.devtype AS typDEVTYPE,
        definfo.powerlevel AS typPWLEVEL,
        definfo.devfactory AS typFACTORY,
        definfo.xinghao AS typDEVSTYLE,
        definfo.findtime AS typFINDDATE,
        definfo.findcontent AS typDEFINFO,
        definfo.slidea AS typDEFREASON,
        definfo.checktime AS typCLEARDATE,
        definfo.checkresult AS typMEASURE
     FROM DEFECT_DEFECTINFO definfo 
     WHERE 
        definfo.orgid = :orgid
    
]]>
</ sql-query >      
</ hibernate-mapping >
对应的java代码
     public  List  queryTypidefdetailsByHibernate(Long loginerOrgid,Date startTime, Date endTime)  {
        Query query 
= this.getSession().getNamedQuery("queryTypidefdetailReportQuerySql");
        query.setLong(
"orgid"new Long(1));
        List result 
= query.list();
        
return result;
    }


Lib 2007-03-29 13:20 发表评论

你可能感兴趣的:(sql,.net,xml,Hibernate)