我尝试使用服务构建器的自定义 sql,但无法从文件 default.xml 获取自定义查询。我尝试调试,但它在 Student1FinderImpl 的 sql 中返回 null。谁能帮我?这是我的代码:default.xml
<?xml version="1.0" encoding="UTF-8"?>
<custom-sql>
<sql id="searchByNameStudent1">
<![CDATA[
SELECT * FROM database_student1 WHERE name= ?
]]>
</sql>
</custom-sql>
public class Student1FinderImpl extends BasePersistenceImpl<Student1> implements Student1Finder {
@SuppressWarnings("unchecked")
public List<Student1> searchByName(String name,int start,int end){
Session session= null;
String sql= "";
try{
//open session
session= openSession();
//set SQL by ID
sql=CustomSQLUtil.get("searchByNameStudent1");
SQLQuery query= session.createSQLQuery(sql);
query.addEntity("Student1", Student1.class);
query.setCacheable(false);
QueryPos qPos= QueryPos.getInstance(query);
qPos.add(name);
System.out.println(query);
return (List<Student1>) QueryUtil.list(query, getDialect(), start, end);
}
catch(Exception ex){
ex.printStackTrace();
return null;
}
finally{
closeSession(session);
}