-->
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.  [ 10 posts ] 
Author Message
 Post subject: Nested Properties as NamedParameters in HQL
PostPosted: Sun Aug 14, 2005 5:29 pm 
Beginner
Beginner

Joined: Mon Aug 01, 2005 3:51 pm
Posts: 22
I'd like to use nested properties as my named parameters in my hql statements. For example,

Code:
select p from Person p where p.address.state.name = :address.state.name


Code:
Person p = new PersonImpl();
Address a = new AddressImpl();
State s = new StateImpl();
s.setName("PA");
a.setState(s);
p.setAddress(a);
query.setProperties(person);


I'm planning on subclassing Query to override setProperties and use BeanUtils in the implementation to handle the nested properties.

My problem is that "." is not allowed in the named parameter within the hql. There is an AST error.

I made a JIRA to allow "." in named parameters. It was reject with the statement, "use Query.setProperties". So I'm really missing something, because I don't understand how that can be used to allow me to use nested properties of the bean to set the named paramaters in the query.



[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 14, 2005 6:24 pm 
Senior
Senior

Joined: Wed Jul 13, 2005 4:31 pm
Posts: 142
Location: Seattle, WA
why not just use...

Code:
select p from Person p where p.address.state.name = :state

with

Code:
query.setString("state", "PA");

or
Code:
query.setString("state", p.getAddress().getState().getName());


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 14, 2005 6:36 pm 
Beginner
Beginner

Joined: Mon Aug 01, 2005 3:51 pm
Posts: 22
I have much more complicated queries than that. Several named parameters at different levels of the object graph of the bean that is passed into Query.setProperties.
I just gave the over simplified example to help demonstrate what I am trying to do.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 2:38 pm 
Beginner
Beginner

Joined: Mon Aug 01, 2005 3:51 pm
Posts: 22
This feature would be incredibly useful for me. There must be some other way to accomplish what I am trying to do since no else seems to be asking for this.
What am I missing?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 2:46 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Query.setProperties()?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 4:21 pm 
Beginner
Beginner

Joined: Mon Aug 01, 2005 3:51 pm
Posts: 22
Okay. So I guess what I am asking is how do I use Query.setProperties. I'm just not getting it.

If I have the Person bean from my original post and call:

Code:
query.setProperties(person)


What would the hql for the query look like that would cause the nested address.state.name property of the passed in person bean to set a named parameter?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 4:47 pm 
Beginner
Beginner

Joined: Mon Aug 01, 2005 3:51 pm
Posts: 22
According to the javadoc for Query.setProperties:

Quote:
Bind the property values of the given bean to named parameters of the query, matching property names with parameter names


For the Person bean in my example, the property name is address.state.name, so accordingly I make the named param be :address.state.name. That throws an AST exception, the details of which I posted in JIRA HHH-836 which was rejected with
Quote:
Use Query.setProperties
I'm trying.

If necessary, I have no problems with having to write my own implementation of Query.setProperties that supports nested properties, but I can't get into the antlr to make it allow the "." character in named params. I looked at the antlr stuff and it frightens me.[/img]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 05, 2005 7:06 pm 
Beginner
Beginner

Joined: Mon Aug 01, 2005 3:51 pm
Posts: 22
Is the answer to my question still

Code:
User Query.setProperties


If so, I'd like change the question to how can I use Query.setProperties to do what I have explained in my previous posts. I've spent considerable amount of time looking at Query.setProperties, and I just don't see it.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 27, 2006 6:51 pm 
Beginner
Beginner

Joined: Mon Aug 01, 2005 3:51 pm
Posts: 22
True or False? Query.setProperties does not support nested properties?

The answer, as far as I can tell, is True.

I would like to write my own implementation that does. I think it would be fairly easy, but I can't use '.' in a named parameter. I added a JIRA to be allowed to and got the response "use Query.setProperties". I would love to, but it doesn't work.


Top
 Profile  
 
 Post subject: Re: Nested Properties as NamedParameters in HQL
PostPosted: Thu Feb 05, 2015 8:57 pm 
Newbie

Joined: Thu Feb 05, 2015 8:54 pm
Posts: 1
Hi guys, I found a solution:

http://stackoverflow.com/questions/28336513/how-to-use-a-nested-property-as-a-named-param-in-a-hibernate-query/


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