Defining own way of mapping SQL result to Object

View: New views
2 Messages — Rating Filter:   Alert me  

Defining own way of mapping SQL result to Object

by agatone () :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I'm sorry maybe this is a simple thing to solve, but I can't find a solution to it - or don't know exactly what too look for.

I've got a SQL result set (from join of two tables order and suborder)

order_id | order_name | suborder_id | suborder_name |
-----------------------------------------------------
1          | ord1           | 1              | subord1           |
-----------------------------------------------------
1          | ord1           | 2              | subord2           |
-----------------------------------------------------
1          | ord1           | 3              | subord3           |
-----------------------------------------------------
2          | ord2           | 4              | subord4           |
-----------------------------------------------------
2          | ord2           | 5              | subord5           |
-----------------------------------------------------

When i map (by session.readAllObjects) that to my class Order (which has @OneToMany of Suborder defined in it) I get collection of 5 objects but I'd like to get collection of 2 Order objects of which each contains collection of it's suborders.

Is that possible to do automatically or I have to loop through all objects and regroup them myself?

Thank you.

P.S.: sorry for resend to the list but i had to subscribe to mailing list

Re: Defining own way of mapping SQL result to Object

by James Sutherland :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Provided the native SQL returns all of the required data, you can set the joinAttributes on the ReadAllQuery (or use hint in JPA) to enable joining with a native SQL query.

You could also use a normal JPQL or Expression query with the joining and have EclipseLink generate the SQL.


agatone wrote:
Hi,

I'm sorry maybe this is a simple thing to solve, but I can't find a solution to it - or don't know exactly what too look for.

I've got a SQL result set (from join of two tables order and suborder)

order_id | order_name | suborder_id | suborder_name |
-----------------------------------------------------
1          | ord1           | 1              | subord1           |
-----------------------------------------------------
1          | ord1           | 2              | subord2           |
-----------------------------------------------------
1          | ord1           | 3              | subord3           |
-----------------------------------------------------
2          | ord2           | 4              | subord4           |
-----------------------------------------------------
2          | ord2           | 5              | subord5           |
-----------------------------------------------------

When i map (by session.readAllObjects) that to my class Order (which has @OneToMany of Suborder defined in it) I get collection of 5 objects but I'd like to get collection of 2 Order objects of which each contains collection of it's suborders.

Is that possible to do automatically or I have to loop through all objects and regroup them myself?

Thank you.

P.S.: sorry for resend to the list but i had to subscribe to mailing list