Hibernate version: 3.1.1
Hi All,
A little background
I am developing a query service based on HQL for my DataBase (DB Contains Identity Information). This service will be used for only data retrieval by many other systems. My DB structure is as follows
Entity A
Single valued Attributes : name, description, status
Multi valued attributes : alternate names, group codes
We represent above structure as following tables
Code:
Table A (PK - entity_id)
entity_id name description status
1 a1 d1 s1
Table B (PK - entity_id, alternate_names)
entity_id alternate_names
1 an1
1 an2
Table C (PK - entity_id, group_code, group_type)
entity_id group_code group_type
1 gc1 gt1
1 gc2 gt2
I am representing my tables in hibernate as per the tables only means
Entity A with attributes as entity_id, name, description, status, set entity B and set entity C
Entity B with attributes as entity_id, alternate_names (composite id calss will be there)
Entity C with attributes as entity_id, group_code, group_type (composite id calss will be there).
My problem
I want to retrieve data as follows this in one HQL
String entity_id, String name, List of (String alternate_names)
ex: 1, a1, List(an1, an2)
Currently I am writing following HQLs
select a.entity_id, a.name, b.alternate_name from A a, B b where a.entity_id=b.entity_id
or
select a.entity_id, a.name, elements(a.alternate_names) from A a
And I am getting the following result
1 a1 an1
1 a1 an2
Here 1 and a1 is repeating and i need to process the result to get 1, a1, list(an1, an2)
Please let me know how I can get
String entity_id, String name, List of (String alternate_names) from a hql or some hql related utility.
I am ready for any suggestions or help or Links. Code changing for me is not a issue as I am still in design phase. But I cannot change the DB.