saperliu / hibernate-generic-dao

Automatically exported from code.google.com/p/hibernate-generic-dao
0 stars 0 forks source link

Alias missed in JPABaseDAO's queries #68

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The alias was missed in the JPABaseDAO's queries.

Such as below query in the method _removeById():

Query query = em().createQuery("select id from " + type.getName() + " where id 
= ?").setParameter(1, id);

Just like the SearchProcessor, it could be:

Query query = em().createQuery("select _it.id from " + type.getName() + " _it 
where _it.id = ?").setParameter(1, id);

Original issue reported on code.google.com by Jirong.Gao on 21 Sep 2010 at 8:58

GoogleCodeExporter commented 9 years ago
Does this cause an error? It had been working in my tests.

Original comment by dwolvert on 22 Sep 2010 at 12:31

GoogleCodeExporter commented 9 years ago
The JPA will complain the syntax error, see below exceptions:

>>>>>>>> excerpt begin >>>>>>>>>>>>>

java.lang.IllegalArgumentException: An exception occurred while creating a 
query in EntityManager: 
Exception Description: Syntax error parsing the query [select id from Shop 
where id = ?1], line 1, column 20: syntax error at [where].
Internal Exception: MismatchedTokenException(77!=78)

>>>>>>>> excerpt end>>>>>>>>>>>>>

I'm using JPA2.0 and EclipseLink, it looks like the EclipseLink complains such 
syntax, I did not test hibernate. However, add alias will satisfy all JPA 
providers.

BTW, if you want to reproduce this error, you need to call removeById() 
directly, or clear the Entity Manager before executing the deletion if call 
remove(). Otherwise, the remove() will try to use cached managed entity without 
using ID.

Original comment by Jirong.Gao on 22 Sep 2010 at 1:48

GoogleCodeExporter commented 9 years ago

Original comment by dwolvert on 1 Oct 2010 at 12:43

GoogleCodeExporter commented 9 years ago

Original comment by dwolvert on 1 Oct 2010 at 12:48

GoogleCodeExporter commented 9 years ago
Fixed for 0.5.2

Original comment by dwolvert on 21 Nov 2010 at 3:33

GoogleCodeExporter commented 9 years ago

Original comment by dwolvert on 22 Nov 2010 at 4:07

GoogleCodeExporter commented 9 years ago

Original comment by dwolvert on 27 Feb 2011 at 5:33