-->
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.  [ 3 posts ] 
Author Message
 Post subject: HQL and nested values
PostPosted: Tue Mar 11, 2008 2:11 pm 
Newbie

Joined: Tue Mar 11, 2008 1:45 pm
Posts: 4
Hi.

I've two classes dao.

Code:
class Addresses{
private Anag foo;
//getter and setter
}

class Anag{

private String name;
//getter and setter

}


The two classes are mapped with two hbm (into addresses.hbm.xml there ia a <many-to-one> relationship obviously).

The question is:

I would execute the following HQL query:

Code:

      StringBuilder query = new StringBuilder();
      query.append("SELECT A");
      query.append(" FROM Addresses as I");
      query.append(" inner join I.anag as A");
      query.append(" where A.name = :foo.name");



But the method session.createQuery(String query) throws an Error and in particular write on console the following message:

Code:
org.hibernate.hql.ast.ErrorCounter.reportError(ErrorCounter.java:33) - ERROR - <AST>:1:148: unexpected AST node: :


Is it possible to refer to the variable "name" into my query and how?

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 11, 2008 10:35 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
":" is just a delimeter for a named parameter and apparently you can't have a dot in it. If you want to refer to other aliases in your query, just use the dot notation. If you want to create a named parameter, use the : and no dots (and of course then you have to set a value too).

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 12, 2008 5:10 am 
Newbie

Joined: Tue Mar 11, 2008 1:45 pm
Posts: 4
cbredesen wrote:
If you want to create a named parameter, use the : and no dots (and of course then you have to set a value too).


Is it possible that there isn't no way to refer to nested value into my named parameter?

I add that I "populate" my parameters using

Code:
query.setProperties(Addresses value)


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