-->
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.  [ 2 posts ] 
Author Message
 Post subject: Multiple entity results with scalar result gives problem
PostPosted: Tue Feb 23, 2010 10:20 am 
Newbie

Joined: Tue Feb 23, 2010 8:42 am
Posts: 2
I need some input, see the following example:
(yes it is silly, but it is for clarity)

The following works properly:

SELECT
{cst1.*}
, {adr1.*}
{cst2.*}
, {adr3.*}
FROM
customer cst1
, address adr1
customer cst2
, address adr2
WHERE
cst1.id = cst2.id

sqlQuery.addEntity( 'cst1', Customer.class);
sqlQuery.addJoin( 'adr1', 'cst1.address');
sqlQuery.addEntity( 'cst2', Customer.class);
sqlQuery.addJoin( 'adr2', 'cst2.address' );

List list = sqlQuery.list()

This results in a List of Object[2] as expected where object[0] is an instance of Customer and object[1] is an instance of Customer.

Now I add a scalarresult and change the query to:

SELECT
{cst1.*}
, {adr1.*}
{cst2.*}
, {adr3.*}
, 'extra data' ed
FROM
customer cst1
, address adr1
customer cst2
, address adr2
WHERE
cst1.id = cst2.id

sqlQuery.addEntity( 'cst1', Customer.class );
sqlQuery.addJoin( 'adr1', 'cst1.address' );
sqlQuery.addEntity( 'cst2', Customer.class );
sqlQuery.addJoin( 'adr2', 'cst2.address' );
sqlQuery.addScalar( 'ed', Hibernate.String ); // added to get the result in the list

List list = sqlQuery.list();

This results in a List of Object[3] as expected BUT object[1] is instance of Address instead of Customer.
So the answer is crippled by adding the scalarresult.

I added an resultranformer to find out if I could correct this behaviour and I found out that in 'normal' conditions (entity only) all the unassembled entities
and there respective aliases are present int the transformTuple method, as tuples, however when you add a Scalarresult the arrays are of different lengths and thus no longer tuples and therefore useless.

Mutiple questions arise:

1: Are Multiple entity results combined with scalar results allowed? If yes what am I doing wrong.
2: What is the use of an resulttransformer if the alias array has no longer te same index as the values array.
I guess this is a bug? Maybe the one causing the inrcorect behaviour of above?

Best Regards, Ton.


Top
 Profile  
 
 Post subject: Re: Multiple entity results with scalar result gives problem
PostPosted: Mon Mar 01, 2010 6:10 am 
Newbie

Joined: Tue Feb 23, 2010 8:42 am
Posts: 2
Quote:
Mutiple questions arise:

1: Are Multiple entity results combined with scalar results allowed? If yes what am I doing wrong.
2: What is the use of an resulttransformer if the alias array has no longer te same index as the values array.
I guess this is a bug? Maybe the one causing the inrcorect behaviour of above?


Problem 1 is solved: The order of adding entities and their joins seems to be of influence, the addEntities have to be declared before the addJoins.

sqlQuery.addEntity( 'cst1', Customer.class );
sqlQuery.addEntity( 'cst2', Customer.class );
sqlQuery.addJoin( 'adr1', 'cst1.address' );
sqlQuery.addJoin( 'adr2', 'cst2.address' );
sqlQuery.addScalar( 'ed', Hibernate.String );

Problem 2 is still a mystery to me, If I add a scalar result the tuples[] and the aliases[] in the result set do not longer match....


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.