-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: bind parameters
PostPosted: Fri Jun 03, 2005 6:36 am 
Beginner
Beginner

Joined: Sat Oct 04, 2003 7:00 am
Posts: 26
Location: Roma,IT
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

when i change from sybase database to mysql the bind parameters don't work correclty i don understand what is the problem but the generated sql appears with :parameter then ? point.

tnx for the help

Hibernate version:
3.0.5

Code between sessionFactory.openSession() and session.close():

...
size = dao.getSociSize(" where UPPER(socio.cognome || ' ' || socio.nome) like :txt", new String[] {"txt"}
, new Object[] {searchTxt});
...

public int getSociSize(String whereClause, String[] names, Object[] params)
throws DAOException {

try {
Query q = getQuery("select count(*) from sic.business.Socio as socio", whereClause, "",names,params);

return( (Integer) q.iterate().next()).intValue();
}
catch(HibernateException ex) {
throw new DAOException(ex);
}
}



protected Query getQuery(String fromClause, String whereClause, String orderClause, String[] names,
Object[] parameters)
throws HibernateException {
Query q = getQuery(fromClause, whereClause, orderClause);

for(int i = 0; i < names.length; i++) {
if(parameters[i].getClass().isArray()) {
q.setParameterList(names[i], (Object[]) parameters[i]);
}
else if(parameters[i] instanceof Collection) {
q.setParameterList(names[i], (Collection) parameters[i]);
}
else {
q.setParameter(names[i], parameters[i]);
}
}

return q;
}

Full stack trace of any exception that occurs:
12:25:35,553 DEBUG AbstractBatcher:290 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
12:25:35,553 DEBUG SQL:324 - /* select count(*) from sic.business.Socio as socio where UPPER(socio.cognome || ' ' || socio.nome) like :txt */ select count(*) as col_0_0_ from socio socio0_ where (UPPER(socio0_.soc_cognome||' '||socio0_.soc_nome)like ? )
Hibernate: /* select count(*) from sic.business.Socio as socio where UPPER(socio.cognome || ' ' || socio.nome) like :txt */ select count(*) as col_0_0_ from socio socio0_ where (UPPER(socio0_.soc_cognome||' '||socio0_.soc_nome)like ? )
12:25:35,616 DEBUG AbstractBatcher:378 - preparing statement
12:25:35,616 DEBUG AbstractBatcher:306 - about to open ResultSet (open ResultSets: 0, globally: 0)
12:25:35,631 DEBUG AbstractBatcher:313 - about to close ResultSet (open ResultSets: 1, globally: 1)
12:25:35,631 DEBUG AbstractBatcher:298 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
12:25:35,631 DEBUG AbstractBatcher:416 - closing statement


Name and version of the database you are using:
Mysql 4.1


Top
 Profile  
 
 Post subject: resolved
PostPosted: Fri Jun 03, 2005 6:44 am 
Beginner
Beginner

Joined: Sat Oct 04, 2003 7:00 am
Posts: 26
Location: Roma,IT
i think mtsql do not support || string concatenation i have replace tem with concat()


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.