-->
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: Advanced HQL
PostPosted: Wed Oct 13, 2004 10:04 am 
Newbie

Joined: Wed Oct 06, 2004 4:15 am
Posts: 16
Hibernate version:
2.1.6

Hi,

I have a class named "Entity", mapped to table "ENTITIES" (see below). I have defined a map collection into "Entity", to obtain properties of an entity, as shown in the following markup

/**
* @hibernate.map name="textAttributes" table="ENTITY_ATTRIBUTES" lazy="true" cascade="all-delete-orphan"
* @hibernate.collection-key column="ENTITY"
* @hibernate.index-many-to-many column="ATTRIBKEY" class="nf.bsf.beans.common.Name"
* @hibernate.collection-element column="ATTRIBVALUE_TEXT" type="java.lang.String"
* @return Map
*/

So, cleanly I have only one entity, and I can map arbitrary properties to this entity.

My problem comes when I want (with HQL) to obtain the entities ordered by the value of a property of the map (i.e. order the entities by a Social Security number). The problem is to order by the values of a "specific" property (i.e. a key in the map)

My first trial is to restrict the rows fetched(to only the properties I want, speaking, Social Security number) by the inner join and then order by these join values...

select entity from Entity entity inner join entity.textAttributes[:key] as entity_textattrs ... group by entity_textattrs

But hibernate complains about that (the error is "unexpected token :key").

Do you have any hints or ideas??.

Thank you very much in advance...

Carlos

CREATE TABLE ENTITIES
(
ID_ENTITY NUMBER(20) NOT NULL,
TYPE NUMBER(20) NOT NULL,
STATUS NUMBER(20) NOT NULL,
CONSTRAINT PK_ENTITIES PRIMARY KEY (ID_ENTITY),
CONSTRAINT FK_TYPE FOREIGN KEY (TYPE) REFERENCES NAMES(ID_NAME),
CONSTRAINT FK_STATUS FOREIGN KEY (STATUS) REFERENCES NAMES(ID_NAME)
);

and

CREATE TABLE ENTITY_ATTRIBUTES
(
ENTITY NUMBER(20) NOT NULL,
ATTRIBKEY NUMBER(20) NOT NULL,
ATTRIBVALUE_TIMESTAMP TIMESTAMP,
ATTRIBVALUE_NUMBER NUMBER,
ATTRIBVALUE_TEXT VARCHAR2(2048),
CONSTRAINT PK_ENTITY_ATTRIBUTES PRIMARY KEY(ENTITY, ATTRIBKEY),
CONSTRAINT FK_ENTITY FOREIGN KEY(ENTITY) REFERENCES ENTITIES(ID_ENTITY),
CONSTRAINT FK_ATTRIBKEY FOREIGN KEY(ATTRIBKEY) REFERENCES NAMES(ID_NAME)
);


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.