Hibernate 利用配置文件配置HQL/SQL

阅读更多
Query.hbm.xml
  
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">  
 
  
 
       
                      FROM      User u  
             WHERE      u.userName = :userName  
         ]]>
          
       
                      SELECT  
                 {u.*}  
             FROM  
                 user u  
             WHERE  
                 u.user_name = :userName  
         ]]>
           
    
  
      

hibernate.cfg.xml

     "-//Hibernate/Hibernate Configuration DTD//EN"
     "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
   

    
         ...
        
       
        
       
         ...
    


Java Code:
String username = "...";
Session session = ...;
Query query = session.getNamedQuery("QueryUser");
//Query query = session.getNamedQuery("SqlQueryUser");
query.setString("name", username);
List userList = query.list();

你可能感兴趣的:(hibernate,query,mapping,xml,hbm)