-->
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.  [ 1 post ] 
Author Message
 Post subject: Projection for map property with specific key in HQL?
PostPosted: Wed Nov 09, 2011 8:52 am 
Newbie

Joined: Tue Nov 08, 2011 7:30 am
Posts: 1
Hi colleagues,

I have an Entity with a property of type map, like so:
Code:
    @org.hibernate.annotations.CollectionOfElements
    @JoinTable(name="E_CUSTOM_ATTR", joinColumns={@JoinColumn(name="E_ID")})
    @org.hibernate.annotations.MapKey(columns=@Column(name="NAME", nullable=false))
    @Column(name="VALUE", nullable=false)
    private Map<String, String> customAttribute;

I know (and value) that I can write a HQL query for instances of my Entity with a givenValue under a specificKey in the map, e.g.
Code:
from Entity entity where entity.customAttribute['specificKey'] = :givenValue

My question is: Is there a way to write a HQL report query that selects values under a specificKey without returning the instantiated entity?
In other words, I would like to write a HQL query that works like
Code:
select customAttribute['specificKey'] from Entity where ...

but this is not supported by HQL.

I know that I can use a SQL query for that
Code:
select custom.VALUE from E_CUSTOM_ATTR custom, ENTITY entity where custom.E_ID = entity.ID and custom.NAME='specificKey'

but I am required to use HQL.

Thanks,

ace130


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.