-->
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: Dynamic query to named query
PostPosted: Tue Apr 22, 2008 10:55 am 
Newbie

Joined: Tue Apr 22, 2008 10:07 am
Posts: 1
Hi all,

I have an issue like this

There is column called URL in my schema in the following format

"file://ServerName/usr/local/tmp/xyz.xml"

I am fetching records based on my server name using 'like' operator as follows

String serverName = SystemConfiguration.getInstance().getName();
Query query = getCurrentSession().createQuery("from InterceptedResource resource where m_resourceIdentifier like '%"
+ serverName
+ "%'");
return query.list();


The server name field is not present in the entity object mapped to the schema.

Currently I am using this as a dynamic query finding the server name at the instant.

Is it possible to change the query as 'named query' inside the HBM file without having server name as an member variable in the mapped class ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 22, 2008 5:11 pm 
Newbie

Joined: Thu Dec 15, 2005 8:31 am
Posts: 10
Try something like this:

String serverName = "%"+SystemConfiguration.getInstance().getName()+"%";
Query query = getCurrentSession().getNamedQuery("SomeName");
query.setParameter( "serverName", serverName );
return query.list();


...
<query name="SomeName" >
<![CDATA[
from InterceptedResource resource where m_resourceIdentifier like :serverName
]]>
</query>
....

In short use parameters in the named query


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.