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/05/30 11:07:31 UTC

Ordering results obtained through query-by-example

Comrades,

  I'm using the OpenJPA query-by-example API, and it works fine unless I order my results. When I do that, I get way too many results. If I search without specifying an order, I get 4 results from a table of 9 rows. If I specify an order, I get 36 results instead. (I get everything four times.) The number I get is always the number I'm supposed to get multiplied by the number of rows.

Has anybody else seen this behavior? I'm trying to figure out if I'm doing something wrong, or if it's a bug in the JPA code. 

Here's my method, if you're interested:

	private final Class<E> persistentClass;

	public List<E> findByExample(
			@NotNull E exampleInstance,
			@Nullable Attribute<E,?>[] excludeProperty,
			SingularAttribute<E,?>… orderFields
	) throws DAORuntimeException { 
		EntityManager entityManager = JpaUtil.getEntityManager();
		OpenJPACriteriaBuilder builder = (OpenJPACriteriaBuilder) entityManager.getCriteriaBuilder();
		CriteriaQuery<E> qDef = builder.createQuery(persistentClass);
		Root<E> from = qDef.from(persistentClass);
		qDef.select(from);
		qDef.where(builder.qbe(from, exampleInstance, excludeProperty)); // query by example
		Query query = entityManager.createQuery(qDef);

		List<Order> orderList = makeOrderList(builder, qDef.from(persistentClass), orderFields);
		if (!orderList.isEmpty()) {
			qDef.orderBy(orderList);
		}

		return (List<E>) query.getResultList();
	}

	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;
	}


If I call it like this, it works fine:

		List<Incident> dIncidentList = incidentDao.findByExample(dExample, null);

If I call it like this, it returns lots of duplicates:

		List<Incident> dIncidentList = incidentDao.findByExample(dExample, null, Incident_.entryTime);

Is it me? Has anyone else seen this bug?


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

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>.
John,

  Good point, but it turns out it doesn't make any difference. I had actually written the code that way. I moved the createQuery() call up to see if that helped, and forgot to move it back down before writing my email. Both ways produce the same result.

— Miguel



On May 30, 2013, at 2:48 AM, Boblitz John wrote:

> Just an idea, but maybe the 
> 
> 	Query query = entityManager.createQuery(qDef);
> 
> Should come after this:
> 
> 	List<Order> orderList = makeOrderList(builder, qDef.from(persistentClass), orderFields);
> 		if (!orderList.isEmpty()) {
> 			qDef.orderBy(orderList);
> 		}
> 
> ?
> 
> Cheers, 
> 
> John
> 
> ---- 
> 
> Who is General Failure, and why is he reading my hard disk?
> 
> 
> 
> 
>> -----Original Message-----
>> From: Miguel Muñoz [mailto:SwingGuy1024@yahoo.com]
>> Sent: Thursday, May 30, 2013 11:08 AM
>> To: users@openjpa.apache.org
>> Subject: Ordering results obtained through query-by-example
>> 
>> Comrades,
>> 
>>  I'm using the OpenJPA query-by-example API, and it works fine unless I
>> order my results. When I do that, I get way too many results. If I search
>> without specifying an order, I get 4 results from a table of 9 rows. If I specify
>> an order, I get 36 results instead. (I get everything four times.) The number I
>> get is always the number I'm supposed to get multiplied by the number of
>> rows.
>> 
>> Has anybody else seen this behavior? I'm trying to figure out if I'm doing
>> something wrong, or if it's a bug in the JPA code.
>> 
>> Here's my method, if you're interested:
>> 
>> 	private final Class<E> persistentClass;
>> 
>> 	public List<E> findByExample(
>> 			@NotNull E exampleInstance,
>> 			@Nullable Attribute<E,?>[] excludeProperty,
>> 			SingularAttribute<E,?>. orderFields
>> 	) throws DAORuntimeException {
>> 		EntityManager entityManager = JpaUtil.getEntityManager();
>> 		OpenJPACriteriaBuilder builder = (OpenJPACriteriaBuilder)
>> entityManager.getCriteriaBuilder();
>> 		CriteriaQuery<E> qDef =
>> builder.createQuery(persistentClass);
>> 		Root<E> from = qDef.from(persistentClass);
>> 		qDef.select(from);
>> 		qDef.where(builder.qbe(from, exampleInstance,
>> excludeProperty)); // query by example
>> 		Query query = entityManager.createQuery(qDef);
>> 
>> 		List<Order> orderList = makeOrderList(builder,
>> qDef.from(persistentClass), orderFields);
>> 		if (!orderList.isEmpty()) {
>> 			qDef.orderBy(orderList);
>> 		}
>> 
>> 		return (List<E>) query.getResultList();
>> 	}
>> 
>> 	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;
>> 	}
>> 
>> 
>> If I call it like this, it works fine:
>> 
>> 		List<Incident> dIncidentList =
>> incidentDao.findByExample(dExample, null);
>> 
>> If I call it like this, it returns lots of duplicates:
>> 
>> 		List<Incident> dIncidentList =
>> incidentDao.findByExample(dExample, null, Incident_.entryTime);
>> 
>> Is it me? Has anyone else seen this bug?
>> 
>> 
>> -------------------------------------------
>> 
>> 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 Boblitz John <jo...@bertschi.com>.
Just an idea, but maybe the 

	Query query = entityManager.createQuery(qDef);

Should come after this:

	List<Order> orderList = makeOrderList(builder, qDef.from(persistentClass), orderFields);
		if (!orderList.isEmpty()) {
			qDef.orderBy(orderList);
		}

?

Cheers, 

John

---- 

Who is General Failure, and why is he reading my hard disk?




> -----Original Message-----
> From: Miguel Muñoz [mailto:SwingGuy1024@yahoo.com]
> Sent: Thursday, May 30, 2013 11:08 AM
> To: users@openjpa.apache.org
> Subject: Ordering results obtained through query-by-example
> 
> Comrades,
> 
>   I'm using the OpenJPA query-by-example API, and it works fine unless I
> order my results. When I do that, I get way too many results. If I search
> without specifying an order, I get 4 results from a table of 9 rows. If I specify
> an order, I get 36 results instead. (I get everything four times.) The number I
> get is always the number I'm supposed to get multiplied by the number of
> rows.
> 
> Has anybody else seen this behavior? I'm trying to figure out if I'm doing
> something wrong, or if it's a bug in the JPA code.
> 
> Here's my method, if you're interested:
> 
> 	private final Class<E> persistentClass;
> 
> 	public List<E> findByExample(
> 			@NotNull E exampleInstance,
> 			@Nullable Attribute<E,?>[] excludeProperty,
> 			SingularAttribute<E,?>. orderFields
> 	) throws DAORuntimeException {
> 		EntityManager entityManager = JpaUtil.getEntityManager();
> 		OpenJPACriteriaBuilder builder = (OpenJPACriteriaBuilder)
> entityManager.getCriteriaBuilder();
> 		CriteriaQuery<E> qDef =
> builder.createQuery(persistentClass);
> 		Root<E> from = qDef.from(persistentClass);
> 		qDef.select(from);
> 		qDef.where(builder.qbe(from, exampleInstance,
> excludeProperty)); // query by example
> 		Query query = entityManager.createQuery(qDef);
> 
> 		List<Order> orderList = makeOrderList(builder,
> qDef.from(persistentClass), orderFields);
> 		if (!orderList.isEmpty()) {
> 			qDef.orderBy(orderList);
> 		}
> 
> 		return (List<E>) query.getResultList();
> 	}
> 
> 	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;
> 	}
> 
> 
> If I call it like this, it works fine:
> 
> 		List<Incident> dIncidentList =
> incidentDao.findByExample(dExample, null);
> 
> If I call it like this, it returns lots of duplicates:
> 
> 		List<Incident> dIncidentList =
> incidentDao.findByExample(dExample, null, Incident_.entryTime);
> 
> Is it me? Has anyone else seen this bug?
> 
> 
> -------------------------------------------
> 
> 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>.
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.

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
> 


Re: Ordering results obtained through query-by-example

Posted by Miguel Muñoz <Sw...@yahoo.com>.
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>.
Pinaki,

 Thank you for looking at this. Here you are:

First, here's the modified method. (I printed out qDef in three different places)

	public List<E> findByExample(
			@NotNull E exampleInstance, 
			@Nullable Attribute<E,?>[] excludeProperty, 
			SingularAttribute<E,?>... orderFields
	) throws DAORuntimeException {
		EntityManager entityManager = JpaUtil.getEntityManager();
		OpenJPACriteriaBuilder builder = (OpenJPACriteriaBuilder) entityManager.getCriteriaBuilder();
		CriteriaQuery<E> qDef = builder.createQuery(persistentClass);
		System.err.println("qDef a = " + qDef);

		Root<E> from = qDef.from(persistentClass);
		qDef.select(from);
		qDef.where(builder.qbe(from, exampleInstance, excludeProperty));
		System.err.println("qDef b = " + qDef);

		List<Order> orderList = makeOrderList(builder, qDef.from(persistentClass), orderFields);
		if (!orderList.isEmpty()) {
			qDef.orderBy(orderList);
		}
		System.err.println("qDef c = " + qDef);

		Query query = entityManager.createQuery(qDef);

		return (List<E>) query.getResultList();
	}

I ran it twice. The first time was with no order specified, where it worked correctly. The second time was with an order.

Here are the first correct results:

qDef a = SELECT * FROM
qDef b = SELECT c FROM company c WHERE c.name = 'ACME'
qDef c = SELECT c FROM company c, company c WHERE c.name = 'ACME'
2993  jobhunt  TRACE  [main] openjpa.jdbc.SQL - <t 1337300467, conn 868537867> executing prepstmnt 1444598836 SELECT t0.id, t0.fax, t0.name, t0.phone, t0.recruiter, t0.website FROM company t0 WHERE (t0.name = ?) [params=(String) ACME]
2994  jobhunt  TRACE  [main] openjpa.jdbc.SQL - <t 1337300467, conn 868537867> [1 ms] spent

Found 1 companies.
id      1: ACME at 555-1212


Here are the second incorrect results:

qDef a = SELECT * FROM
qDef b = SELECT c FROM company c WHERE c.name = 'ACME'
qDef c = SELECT c FROM company c, company c WHERE c.name = 'ACME' ORDER BY c.name
2997  jobhunt  TRACE  [main] openjpa.jdbc.SQL - <t 1337300467, conn 868537867> executing prepstmnt 1049496898 SELECT t0.id, t0.fax, t0.name, t0.phone, t0.recruiter, t0.website, t1.name FROM company t0 CROSS JOIN company t1 WHERE (t0.name = ?) ORDER BY t1.name ASC [params=(String) ACME]
2998  jobhunt  TRACE  [main] openjpa.jdbc.SQL - <t 1337300467, conn 868537867> [1 ms] spent

Found 4 companies.
id      1: ACME at 555-1212
id      1: ACME at 555-1212
id      1: ACME at 555-1212
id      1: ACME at 555-1212

The qDef values look right. I don't know why it added a join to the actual SQL.
 
On May 30, 2013, at 10:54 AM, Pinaki Poddar wrote:

> please post 
>  1. the criteria query i.e. the output of System.err.println(qDef);
>      it should print a JPQL-like string
> 
>  2. the SQL generated at execution with bind parameters. OpenJPA will print
> the SQL if configured as follows
>        <property name="openjpa.Log" value="SQL=TRACE">
>        <property name="openjpa.ConnectionFactoryProperties"
> value="PrintParameters=true"/>
> 
> 
> 
> 
> 
> 
> -----
> Pinaki Poddar
> Chair, Apache OpenJPA Project
> --
> View this message in context: http://openjpa.208410.n2.nabble.com/Ordering-results-obtained-through-query-by-example-tp7584043p7584046.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 Pinaki Poddar <pp...@apache.org>.
please post 
  1. the criteria query i.e. the output of System.err.println(qDef);
      it should print a JPQL-like string

  2. the SQL generated at execution with bind parameters. OpenJPA will print
the SQL if configured as follows
        <property name="openjpa.Log" value="SQL=TRACE">
        <property name="openjpa.ConnectionFactoryProperties"
value="PrintParameters=true"/>


   



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