You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Miguel Muñoz <Sw...@yahoo.com> on 2013/06/01 10:01:33 UTC

Re: Ordering results obtained through query-by-example

Pinaki,

  My makeOrderList() method looks like this:

	private List<Order> makeOrderList(
			CriteriaBuilder builder, 
			Root<E> root, 
			SingularAttribute<E, ?>[] pOrderFields
	) {
		List<Order> orderList = new LinkedList<>();
		for (SingularAttribute<E, ?> attribute: pOrderFields) {
			orderList.add(builder.asc(root.get(attribute)));
		}
		return orderList;
	}

I don't know how to specify an order without using the root to get the attribute. Am I doing something wrong in this method?

— Miguel



On May 31, 2013, at 10:46 AM, Pinaki Poddar wrote:

> Most likely it is a programming error.
> 
>>            List<Order> orderList = makeOrderList(builder,
>> qDef.from(persistentClass), orderFields);
> 
> this call causes a side-effect of CROSS JOIN which is possibly not your
> intention.  Your code has already called
>>   Root<E> from = qDef.from(persistentClass); 
> few lines earlier. While passing argument to makeOrderList(...) the second
> argument joins 'persistentClass' again.
> 
> 
> Please change the call argument to remove the side-effect and see if that
> changes anything.
> 
> 
> 
> 
> 
> 
> 
> 
> 
> -----
> Pinaki Poddar
> Chair, Apache OpenJPA Project
> --
> View this message in context: http://openjpa.208410.n2.nabble.com/Ordering-results-obtained-through-query-by-example-tp7584043p7584058.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.

-------------------------------------------

Miguel Muñoz
SwingGuy1024@yahoo.com
323/225-7285

-------------------------------------------

The Sun, with all those planets revolving around it and dependent on it, can still ripen a vine of grapes like it had nothing else to do in the world.

  -- Galileo

-------------------------------------------

There are seven sins in the world.
    Wealth without work.
    Pleasure without conscience.
    Knowledge without character.
    Commerce without morality.
    Science without humanity.
    Worship without sacrifice.
    Politics without principle. 

  -- Mohandas Gandhi

-------------------------------------------

If tyranny and oppression come to this land, it will come in the guise of fighting a foreign enemy.

  -- James Madison



Re: Ordering results obtained through query-by-example

Posted by Miguel Muñoz <Sw...@yahoo.com>.
Got it. That fixed the problem of the superfluous JOIN, and I got the correct results, but I don't necessarily get them in the right order. But I'll be posting a separate issue about that in a few days. Thank you all for your help.

— Miguel


On Jun 3, 2013, at 1:37 AM, Boblitz John wrote:

> Hello again,
> 
> You invoke the method makeOrderList as: 
> 
> 	List<Order> orderList = makeOrderList(builder,  qDef.from(persistentClass), orderFields);
> 
> Root was declared and initialized with:
> 	
> 	Root<E> from = qDef.from(persistentClass);
> 
> So I think Pinaki wants you to replace the "qDef.from(persistentClass)" in makeOrderList with "from":
> 
> 	List<Order> orderList = makeOrderList(builder,  from, orderFields);
> 
> Cheers
> 
> John
> 
>> -----Original Message-----
>> From: Miguel Muñoz [mailto:SwingGuy1024@yahoo.com]
>> Sent: Saturday, June 01, 2013 10:02 AM
>> To: users@openjpa.apache.org
>> Subject: Re: Ordering results obtained through query-by-example
>> 
>> Pinaki,
>> 
>>  My makeOrderList() method looks like this:
>> 
>> 	private List<Order> makeOrderList(
>> 			CriteriaBuilder builder,
>> 			Root<E> root,
>> 			SingularAttribute<E, ?>[] pOrderFields
>> 	) {
>> 		List<Order> orderList = new LinkedList<>();
>> 		for (SingularAttribute<E, ?> attribute: pOrderFields) {
>> 			orderList.add(builder.asc(root.get(attribute)));
>> 		}
>> 		return orderList;
>> 	}
>> 
>> I don't know how to specify an order without using the root to get the
>> attribute. Am I doing something wrong in this method?
>> 
>> - Miguel
>> 
>> 
>> 
>> On May 31, 2013, at 10:46 AM, Pinaki Poddar wrote:
>> 
>>> Most likely it is a programming error.
>>> 
>>>>           List<Order> orderList = makeOrderList(builder,
>>>> qDef.from(persistentClass), orderFields);
>>> 
>>> this call causes a side-effect of CROSS JOIN which is possibly not
>>> your intention.  Your code has already called
>>>>  Root<E> from = qDef.from(persistentClass);
>>> few lines earlier. While passing argument to makeOrderList(...) the
>>> second argument joins 'persistentClass' again.
>>> 
>>> 
>>> Please change the call argument to remove the side-effect and see if
>>> that changes anything.
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> -----
>>> Pinaki Poddar
>>> Chair, Apache OpenJPA Project
>>> --
>>> View this message in context:
>>> http://openjpa.208410.n2.nabble.com/Ordering-results-obtained-through-
>>> query-by-example-tp7584043p7584058.html
>>> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>> 
>> -------------------------------------------
>> 
>> Miguel Muñoz
>> SwingGuy1024@yahoo.com
>> 323/225-7285
>> 
>> -------------------------------------------
>> 
>> The Sun, with all those planets revolving around it and dependent on it, can
>> still ripen a vine of grapes like it had nothing else to do in the world.
>> 
>>  -- Galileo
>> 
>> -------------------------------------------
>> 
>> There are seven sins in the world.
>>    Wealth without work.
>>    Pleasure without conscience.
>>    Knowledge without character.
>>    Commerce without morality.
>>    Science without humanity.
>>    Worship without sacrifice.
>>    Politics without principle.
>> 
>>  -- Mohandas Gandhi
>> 
>> -------------------------------------------
>> 
>> If tyranny and oppression come to this land, it will come in the guise of
>> fighting a foreign enemy.
>> 
>>  -- James Madison
>> 
> 

-------------------------------------------

Miguel Muñoz
SwingGuy1024@yahoo.com
323/225-7285

-------------------------------------------

The Sun, with all those planets revolving around it and dependent on it, can still ripen a vine of grapes like it had nothing else to do in the world.

  -- Galileo

-------------------------------------------

There are seven sins in the world.
    Wealth without work.
    Pleasure without conscience.
    Knowledge without character.
    Commerce without morality.
    Science without humanity.
    Worship without sacrifice.
    Politics without principle. 

  -- Mohandas Gandhi

-------------------------------------------

If tyranny and oppression come to this land, it will come in the guise of fighting a foreign enemy.

  -- James Madison




RE: Ordering results obtained through query-by-example

Posted by Pinaki Poddar <pp...@apache.org>.
> So I think Pinaki wants you to replace the "qDef.from(persistentClass)" in
makeOrderList with "from": 

correct. 





-----
Pinaki Poddar
Chair, Apache OpenJPA Project
--
View this message in context: http://openjpa.208410.n2.nabble.com/Ordering-results-obtained-through-query-by-example-tp7584043p7584062.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

RE: Ordering results obtained through query-by-example

Posted by Boblitz John <jo...@bertschi.com>.
Hello again,

You invoke the method makeOrderList as: 

	List<Order> orderList = makeOrderList(builder,  qDef.from(persistentClass), orderFields);

Root was declared and initialized with:
	
	Root<E> from = qDef.from(persistentClass);

So I think Pinaki wants you to replace the "qDef.from(persistentClass)" in makeOrderList with "from":

	List<Order> orderList = makeOrderList(builder,  from, orderFields);

Cheers

John

> -----Original Message-----
> From: Miguel Muñoz [mailto:SwingGuy1024@yahoo.com]
> Sent: Saturday, June 01, 2013 10:02 AM
> To: users@openjpa.apache.org
> Subject: Re: Ordering results obtained through query-by-example
> 
> Pinaki,
> 
>   My makeOrderList() method looks like this:
> 
> 	private List<Order> makeOrderList(
> 			CriteriaBuilder builder,
> 			Root<E> root,
> 			SingularAttribute<E, ?>[] pOrderFields
> 	) {
> 		List<Order> orderList = new LinkedList<>();
> 		for (SingularAttribute<E, ?> attribute: pOrderFields) {
> 			orderList.add(builder.asc(root.get(attribute)));
> 		}
> 		return orderList;
> 	}
> 
> I don't know how to specify an order without using the root to get the
> attribute. Am I doing something wrong in this method?
> 
> - Miguel
> 
> 
> 
> On May 31, 2013, at 10:46 AM, Pinaki Poddar wrote:
> 
> > Most likely it is a programming error.
> >
> >>            List<Order> orderList = makeOrderList(builder,
> >> qDef.from(persistentClass), orderFields);
> >
> > this call causes a side-effect of CROSS JOIN which is possibly not
> > your intention.  Your code has already called
> >>   Root<E> from = qDef.from(persistentClass);
> > few lines earlier. While passing argument to makeOrderList(...) the
> > second argument joins 'persistentClass' again.
> >
> >
> > Please change the call argument to remove the side-effect and see if
> > that changes anything.
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > -----
> > Pinaki Poddar
> > Chair, Apache OpenJPA Project
> > --
> > View this message in context:
> > http://openjpa.208410.n2.nabble.com/Ordering-results-obtained-through-
> > query-by-example-tp7584043p7584058.html
> > Sent from the OpenJPA Users mailing list archive at Nabble.com.
> 
> -------------------------------------------
> 
> Miguel Muñoz
> SwingGuy1024@yahoo.com
> 323/225-7285
> 
> -------------------------------------------
> 
> The Sun, with all those planets revolving around it and dependent on it, can
> still ripen a vine of grapes like it had nothing else to do in the world.
> 
>   -- Galileo
> 
> -------------------------------------------
> 
> There are seven sins in the world.
>     Wealth without work.
>     Pleasure without conscience.
>     Knowledge without character.
>     Commerce without morality.
>     Science without humanity.
>     Worship without sacrifice.
>     Politics without principle.
> 
>   -- Mohandas Gandhi
> 
> -------------------------------------------
> 
> If tyranny and oppression come to this land, it will come in the guise of
> fighting a foreign enemy.
> 
>   -- James Madison
>