-->
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 variables Question
PostPosted: Fri Jan 20, 2006 5:40 pm 
Beginner
Beginner

Joined: Tue Sep 06, 2005 5:16 pm
Posts: 24
Location: USA
Hibernate version:2.1.X


Code in Persister:

public List getParent(String ssn, String pin) throws HibernateException,Exception {
List result = null;
try {
Session session = HibernateSessionFactory.currentSession();
StringBuffer sql = new StringBuffer();
sql.append("from CswCaseParent1 as cp where (cp.clientSsnId = ").append(ssn)
.append(" AND cp.clientPinId = ").append(pin)
.append(") OR (cp.respondentSsnId = ").append(ssn)
.append(" AND cp.respondentPinId =").append(pin).append(")");
Query q1 = session.createQuery(sql.toString());
result = q1.list();

} catch (HibernateException e) {
log.error("HibernateException occured while getting the parent information...", e);
throw new HibernateException("HibernateException occured while getting the parent information...",e);
} catch (Exception e) {
log.error("Exception occured while getting the parent information..." , e);
throw new Exception("Exception occured while getting the parent information...",e);
}finally {
//log.debug("closing the HibernateSessionFactory..");
try {
HibernateSessionFactory.closeSession();
} catch (Exception e) {
throw new Exception("Exception occured while closing the HibernateSessionFactory..",e);
}

}
return result;
}



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

public static Session currentSession() throws HibernateException {
Session session = (Session) threadLocal.get();

if (session == null) {
if (sessionFactory == null) {
try {
//cfg.configure(CONFIG_FILE_LOCATION);
cfg.configure(new File("C:/Program Files/WebSphere/AppServer/hibernate.cfg.xml"));
sessionFactory = cfg.buildSessionFactory();
}
catch (Exception e) {
log.error("%%%% Error Creating SessionFactory %%%%", e);
throw new HibernateException(e);

}
}
session = sessionFactory.openSession();
threadLocal.set(session);
}

return session;
}

/**
* Close the single hibernate session instance.
*
* @throws HibernateException
*/
public static void closeSession() throws HibernateException,Exception {
Session session = (Session) threadLocal.get();
threadLocal.set(null);

try
{
if (session != null) {
session.close();
}
}
catch (Exception e) {
log.error("%%%% Error Closing SessionFactory %%%%", e);
throw new Exception("Exception while Closing SessionFactory..",e);
}
}



Full stack trace of any exception that occurs:

Not Exception.Issue related to performance



Name and version of the database you are using:

Oracle 9i



The generated SQL (show_sql=true):

select cswcasepar0_.CASE_ID as CASE_ID, cswcasepar0_.COUNTY_CD as COUNTY_CD, cswcasepar0_.CLIENT_SSN_ID as CLIENT_S3_, cswcasepar0_.PIN_ID as PIN_ID, cswcasepar0_.CLIENT_PIN_ID as CLIENT_P5_, cswcasepar0_.CLIENT_NM as CLIENT_NM, cswcasepar0_.NET_DUE_AMT as NET_DUE_7_, cswcasepar0_.RESPONDENT_BIRTH_DT as RESPONDE8_, cswcasepar0_.RESPONDENT_ADDRESS_TYPE_CD as RESPONDE9_, cswcasepar0_.RESPONDENT_UPDATE_SSN_ID as RESPOND10_, cswcasepar0_.PAYMENT_FROM_DT as PAYMENT11_, cswcasepar0_.PAYMENT_TO_DT as PAYMENT12_, cswcasepar0_.RESPONDENT_SSN_ID as RESPOND13_, cswcasepar0_.RESPONDENT_PIN_ID as RESPOND14_, cswcasepar0_.RESPONDENT_NM as RESPOND15_, cswcasepar0_.CREATE_DT as CREATE_DT, cswcasepar0_.MODIFY_DT as MODIFY_DT, cswcasepar0_.CONTROL_CYCLE_NBR as CONTROL18_, cswcasepar0_.NCP_UPDATE_DT as NCP_UPD19_ from CSW_CASE_PARENT cswcasepar0_ where ((cswcasepar0_.CLIENT_SSN_ID='050547490' )AND(cswcasepar0_.CLIENT_PIN_ID='26021' ))OR((cswcasepar0_.RESPONDENT_SSN_ID='050547490' )AND(cswcasepar0_.RESPONDENT_PIN_ID='26021' ))




Hi there,
We are developing a hibernate(2.1.X) based application.We got a message from our DBA to use
Quote:
bind variables, not literals
.
What exactly that means.Here is my code ..What exactly i should do to use bind variables?

Any help is much appreciated.Thanks In Advance


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 20, 2006 5:50 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Have a look at this documentation http://www.hibernate.org/hib_docs/v3/reference/en/html/queryhql.html

Bind variables mean essentially the same thing they mean in SQL, JDBC, etc: parameters


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.