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: Simple Map Query not working...
PostPosted: Wed Aug 06, 2008 2:56 pm 
Newbie

Joined: Tue Mar 20, 2007 5:27 pm
Posts: 12
Hi all, I have a fairly simple Map HQL query that isn't work due to badly generated SQL. Here's the relevant part of the class I am trying to query.
Code:

public class Account {
  ...
  @OneToMany(cascade = CascadeType.ALL)
  //javax mapkey
  @MapKey(name="propertyName")
  private Map<String, AdditionalProperty> additionalProperties;

...
}

public class AdditionalProperty {
  ...

  private String propertyName;
  private String propertyValue;

  ...
}

//Querying with HQL of:
"FROM Account ac WHER ac.additionalProperties['someValue'],propertyValue = 'value'"


This gets through hibernate alright but it throughs an SQL error because the it doesn't join the AdditionalProperty class correctly. The sql it generates that is bad is as follows: (just including FROM clause on...)
Code:
"from Account account0_, Account_AdditionalProperty additional1_, AdditionalProperty additional2_ where account0_.id=additional1_.Account_id and additional1_.null = 'someValue' and additional1_.additionalProperties_id=additional2_.id  and additional2_.propertyValue=?"


The wrong part of the sql is "additional1_.null = 'someValue'". Obviously null is not a column name, and its not joined by the key anyways, but the account id, so whats it trying to do here?

Loading objects up works just fine and all the values are correct, but why can't I run this query? I can't see anything that I'm missing compared to the examples.

Thanks for the help!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 06, 2008 3:47 pm 
Newbie

Joined: Tue Mar 20, 2007 5:27 pm
Posts: 12
Ok, doing some more testing it seems like MapKey is being completly ignored when running HQL statements. I tried making this like the example (adding mappedBy) and it gives almost the exact same results. Only difference being that its only joining one table now since I don't have the join table anymore.

But the SQL is still wrong and still has addtional1_.null = 'someValue' in it. What am I missing here?!?


Last edited by nstuart on Wed Aug 06, 2008 3:49 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 06, 2008 3:49 pm 
Newbie

Joined: Tue Mar 20, 2007 5:27 pm
Posts: 12
Oh, also, I have tested this using version annotation versions 3.3.0 and 3.3.1 on jdk6 against MySQL.


Top
 Profile  
 
 Post subject: HQL querying on map key and MapKey annotation
PostPosted: Mon Nov 03, 2008 7:31 pm 
Newbie

Joined: Wed Oct 29, 2008 6:29 am
Posts: 7
Location: Liège, BE
I have the same problem and it's really blocking.

Can someone comment on whether MapKey annotations should work with that kind of queries ?
If not, what kind of annotation/configuration would enable this ?

thanks a lot


Top
 Profile  
 
 Post subject: Re: HQL querying on map key and MapKey annotation
PostPosted: Thu Nov 27, 2008 10:20 pm 
Newbie

Joined: Tue Jan 16, 2007 3:44 pm
Posts: 10
I also have the exact same problem. I just learned how to use @MapKey, but now it was stopped by its query. Anybody can give some hint? Really appreciate it.

Have a great Thanksgiving night!


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.