我有以下服务方法:
public List<ClientView> getClientList(boolean isGlobal, Client client, Address address) {
List<ClientView> clientList = null;
try{
Query CQuery;
String queryForClientList= "SELECT NEW org.domain.carsclass.pojo.ClientView(c.clientId, c.name, c.lastName,c.taxNo, a.mobilePhone, " +
"a.town, a.postCode, a.addressLine1, a.clientAddress.companyId, "+myParam.getCompany().getCompanyId()+" ) FROM Address a INNER JOIN a.client c ";
System.out.print(queryForClientList);
System.out.print("Company" + myParam.getCompany().getCompanyId());
if(isGlobal==false)
queryForClientList += "WHERE a.clientAddress.companyId="+myParam.getCompany().getCompanyId()+" ";
else {
queryForClientList += "WHERE ( a.clientAddress.companyId="+myParam.getCompany().getCompanyId()+" or " +
"NOT EXISTS (SELECT a2.clientAddress.clientId, a2.clientAddress.companyId FROM Address a2 " +
"WHERE a2.client = c AND a2.clientAddress.companyId = "+myParam.getCompany().getCompanyId()+")) ";
}
if(client.getClientId() != null && !client.getClientId().toString().isEmpty())
queryForClientList += "and c.clientId = '"+client.getClientId()+"%' ";
if(client.getName() != null && !client.getName().isEmpty() )
queryForClientList += "and c.name like '"+client.getName()+"%' ";
if(client.getLastName() != null && !client.getLastName().isEmpty())
queryForClientList += "and c.lastName like '"+client.getLastName()+"%' ";
if(client.getTaxNo() != null && !client.getTaxNo().isEmpty())
queryForClientList += "and c.taxNo like '"+client.getTaxNo()+"%' ";
if(address.getMobilePhone() != null && !address.getMobilePhone().isEmpty())
queryForClientList += "and a.mobilePhone like '"+address.getMobilePhone()+"%' ";
if(address.getTown()!= null && !address.getTown().isEmpty())
queryForClientList += "and a.town like '"+address.getTown()+"%' ";
if(address.getPostCode() != null && !address.getPostCode().isEmpty())
queryForClientList += "and a.postCode like '"+address.getPostCode()+"%' ";
if(address.getAddressLine1()!= null && !address.getAddressLine1().isEmpty())
queryForClientList += "and a.addressLine1 like '"+address.getAddressLine1()+"%' ";
if(isGlobal == false)
queryForClientList += "ORDER BY c.name, c.lastName ASC";
else
queryForClientList += "GROUP BY c.clientId ORDER BY c.clientId DESC";
CQuery = entityManager.createQuery(queryForClientList).setMaxResults(20);
System.out.print(queryForClientList);
clientList = (List<ClientView>) CQuery.getResultList();
System.out.print(queryForClientList);
} catch (PersistenceException e) {
System.out.print("PersistenceException " + e.getMessage());
}
return clientList;
}
但是在生成以下日志后它会返回一个空列表。
10:15:04,478 WARN [org.hibernate.engine.jdbc.spi.SqlExceptionHelper](http-localhost-127.0.0.1-8080-1)SQL错误:0,SQLState:null
10:15:04,478 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper](http-localhost-127.0.0.1-8080-1)javax.resource.ResourceException:IJ000460:检查事务时出错
10:15:04,606 INFO [stdout](http-localhost-127.0.0.1-8080-1)SELECT NEW org.domain.carsclass.pojo.ClientView(c.clientId,c.name,c.lastName,c .taxNo,a.mobilePhone,a.town,a.postCode,a.addressLine1,a.clientAddress.companyId,1)FROM Address IN INNER JOIN a.client c Company1
PersistenceException org.hibernate.exception.GenericJDBCException:无法打开连接
我想我在catch块中遇到错误。
这是如何引起的?如何解决?