posted 16 years ago
Hi,
I have this similar problem but the list that i need to pass is a collection of Objects(User-Defined) What exactly I have to do make this run.
This is my code.
private List<Coverage> getListOfCompanies(
List<PartyRelationship> listOfAnalyst)
throws TiNAException {
Coverage pojo = null;
HibernateConnection hc = null;
StringBuilder sqllist = new StringBuilder();
for(PartyRelationship pojoObj : listOfAnalyst)
sqllist.append(pojoObj.getId().getRelPartyId() + ",");
sqllist.delete(sqllist.length()-1, sqllist.length());
try {
hc = ConnectionManager.getConnection(ConnectionManager.QUANTUM);
} catch (ConnectionNotFoundException ex) {
throw new TiNAException("Could not get connection: " +
ex.getMessage());
}
Session session = hc.getSession();
Transaction tx = session.beginTransaction();
String query = "from " + Coverage.class.getCanonicalName() +
" c where c.id in(:sqllist)";
List<Coverage> listofCompanyIds = session.createQuery(query).setParameter("sqllist", sqllist.toString()).list();
if (!listofCompanyIds.isEmpty() || (listofCompanyIds != null)) {
tx.commit();
session.close();
return listofCompanyIds;
} else {
throw new TiNAException(
"Could not find PartyRelationShip instance!");
}
}
I am actually trying to get generate a list of paramters and seperate it wid comma so that it can be passed to the sql statement in the IN clause.
But i belive this is wrong.
How can i directly pass the listOfAnalyst -collection object directly in the query?Also let me know how to i run this on HQL editor .
When i run this on HQL editor
from Coverage c where c.id in( 100000007, 100000199, 100000704, 100001101, 100002169,
100002209, 100002298, 100002401, 100002427, 100002674, 100002691,100002806,100003009, 100651750
)
it says com.sybase.jdbc2.jdbc.SybSQLException: Incorrect syntax near ','.
[ August 20, 2007: Message edited by: Nilesh Raje ]
[ August 20, 2007: Message edited by: Nilesh Raje ]
Thanks and Regards,<br />Nilesh<br />SCJP 1.4, SCWCD 1.4