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.  [ 5 posts ] 
Author Message
 Post subject: multiples setParameter
PostPosted: Fri Jul 04, 2008 7:03 am 
Newbie

Joined: Thu Jul 03, 2008 5:02 am
Posts: 5
Hi everybody,

I have this method:

public String NomeModello (String intestazione, String titleFont, String titleColor, String titleBack, String zonaA, String zonaB, String zonaC, String footer)throws Exception{
String nomeModello = null;
try{
return (String)manager.createQuery("select l.path_modello_layout from Layout l where l.intestazione_layout = :x and l.font_layout = :y").setParameter("x",intestazione).getSingleResult();
}catch (Exception e){

}

return nomeModello;

}

How can i make to set all other query's parameters.

Just for understand better (i hope)

return (String)manager.createQuery("select l.path_modello_layout from Layout l where l.intestazione_layout = :x and l.font_layout = :y").setParameter("x",intestazione).getSingleResult(),setParameter("y",titleFont)...

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 07, 2008 8:40 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
I'm not too sure what the problem is?

Setting parameters in an HQL query is pretty straight forward. Just get the information from the client, and set the parameter in the query:

From the Hibernate Tutorial on Using HQL and Creating Hibernate Queries

Code:
Session session = HibernateUtil.beginTransaction();
String loginName = "mj";
String hql="from User where loginName = :name";
Query query = session.createQuery(hql);
query.setString("name", loginName);
Object o = query.uniqueResult();
User user = (User)o;
System.out.println(user.getLoginName());
HibernateUtil.commitTransaction();


What is the specific problem you are having?

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 07, 2008 8:44 am 
Newbie

Joined: Thu Jul 03, 2008 5:02 am
Posts: 5
Thank you.
this is not exactly what i want but i have found the right way.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 07, 2008 9:14 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Well, don't leave us in the dark! If you figured it out, post back and let everyone know what worked!

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 07, 2008 10:30 am 
Newbie

Joined: Thu Jul 03, 2008 5:02 am
Posts: 5
public String NomeModelloDAO (String headerVal, String footerVal, String titleFontVal, String titleColorVal, String titleSfondoVal, String zonaAVal, String zonaBVal, String zonaCVal)throws Exception{
String nomeModello = null;
try{
Query q = manager.createQuery("select l.path_modello_layout from Layout l where l.intestazione_layout = :x" +
" and l.pie_di_pagina_layout = :p and l.font_layout = :y" +
" and l.colore_testo_layout = :c and l.sfondo_titolo_layout = :s" +
" and l.parte_a_layout = :pa and l.parte_b_layout = :pb " +
" and l.parte_c_layout = :pc");
q.setParameter("x", headerVal);
q.setParameter("p", footerVal);
q.setParameter("y", titleFontVal);
q.setParameter("c", titleColorVal);
q.setParameter("s", titleSfondoVal);
q.setParameter("pa", zonaAVal);
q.setParameter("pb", zonaBVal);
q.setParameter("pc", zonaCVal);
nomeModello = (String)q.getSingleResult();
}catch (Exception e){
log.error("NomeModelloDao() - Failed to find the modello: " + e);
throw e;
}
return nomeModello;

}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.