8 个解决方案
#1
上个图,看看什么情况;
#2
实体的联合主键
查询语句
数据库数据
视图语句
查询结果
#3
你使用的 左连接,出现空值也是正常的;
#4
别的结果都有就那一条为null,我们旧版系统用hibernate查的可以查到
#5
旧版系统hibernate可以查到这条数据,新版用的jpa就不行了。怎么解决?
#6
执行的是同一条SQL 吗?
#7
这是以前的方法
public int select(Object paramObject, String dataName, String condition,
ArrayList orderByList, String orderMethod, int pageNumber,
int pageSize) throws Exception {
Session session = null;
try {
session = HibernateUtil.currentSession(sessionFactoryId);
String queryString = "from " + dataName + " a where";
Class paramClass = paramObject.getClass();
ArrayList paramValues = new ArrayList();
Field[] paramFields = paramClass.getDeclaredFields();
for (int i = 0; i < paramFields.length; i++) {
String tempString = paramFields[i].getName();
if(tempString != null && !"readonly".equals(tempString) && !"sfysj".equals(tempString)){
tempString = "get" + tempString.substring(0, 1).toUpperCase() +
tempString.substring(1, tempString.length());
Object tempValue = paramClass.getMethod(tempString,
null).invoke(paramObject, null);
if ( (tempValue != null) && (!tempValue.equals(""))) {
queryString += " a." + paramFields[i].getName() + " " +
condition +
" ? and";
if (condition.equals("like")) {
tempValue = "%" + tempValue + "%";
}
paramValues.add(paramValues.size(), tempValue);
}
}
}
if (queryString.endsWith("where")) {
int nPlace = queryString.lastIndexOf("where");
queryString = queryString.substring(0, nPlace - 1);
}
if (queryString.endsWith("and")) {
int nPlace = queryString.lastIndexOf("and");
queryString = queryString.substring(0, nPlace - 1);
}
String countQuery = queryString;
if (orderByList != null) {
queryString = queryString + " order by";
for (int i = 0; i < orderByList.size(); i++) {
String tempString = (i == 0) ? " " : ", ";
queryString = queryString + tempString +
(String) orderByList.get(i) +
" " + orderMethod;
}
}
return executeSelect(queryString, countQuery, paramValues,
pageNumber,
pageSize);
}
catch (Exception e) {
throw e;
}
finally {
HibernateUtil.closeSession();
}
}
#8
最后生成的 SQL 语句是一样的吗?
#1
上个图,看看什么情况;
#2
实体的联合主键
查询语句
数据库数据
视图语句
查询结果
#3
你使用的 左连接,出现空值也是正常的;
#4
别的结果都有就那一条为null,我们旧版系统用hibernate查的可以查到
#5
旧版系统hibernate可以查到这条数据,新版用的jpa就不行了。怎么解决?
#6
执行的是同一条SQL 吗?
#7
这是以前的方法
public int select(Object paramObject, String dataName, String condition,
ArrayList orderByList, String orderMethod, int pageNumber,
int pageSize) throws Exception {
Session session = null;
try {
session = HibernateUtil.currentSession(sessionFactoryId);
String queryString = "from " + dataName + " a where";
Class paramClass = paramObject.getClass();
ArrayList paramValues = new ArrayList();
Field[] paramFields = paramClass.getDeclaredFields();
for (int i = 0; i < paramFields.length; i++) {
String tempString = paramFields[i].getName();
if(tempString != null && !"readonly".equals(tempString) && !"sfysj".equals(tempString)){
tempString = "get" + tempString.substring(0, 1).toUpperCase() +
tempString.substring(1, tempString.length());
Object tempValue = paramClass.getMethod(tempString,
null).invoke(paramObject, null);
if ( (tempValue != null) && (!tempValue.equals(""))) {
queryString += " a." + paramFields[i].getName() + " " +
condition +
" ? and";
if (condition.equals("like")) {
tempValue = "%" + tempValue + "%";
}
paramValues.add(paramValues.size(), tempValue);
}
}
}
if (queryString.endsWith("where")) {
int nPlace = queryString.lastIndexOf("where");
queryString = queryString.substring(0, nPlace - 1);
}
if (queryString.endsWith("and")) {
int nPlace = queryString.lastIndexOf("and");
queryString = queryString.substring(0, nPlace - 1);
}
String countQuery = queryString;
if (orderByList != null) {
queryString = queryString + " order by";
for (int i = 0; i < orderByList.size(); i++) {
String tempString = (i == 0) ? " " : ", ";
queryString = queryString + tempString +
(String) orderByList.get(i) +
" " + orderMethod;
}
}
return executeSelect(queryString, countQuery, paramValues,
pageNumber,
pageSize);
}
catch (Exception e) {
throw e;
}
finally {
HibernateUtil.closeSession();
}
}
#8
最后生成的 SQL 语句是一样的吗?