[
http://opensource.atlassian.com/projects/hibernate/browse/EJB-361?page=co...
]
John Sublette commented on EJB-361:
-----------------------------------
I just ran into what looks like this problem also. I tracked it down to the
QueryImpl.isPositionalParameter() function. It looks to me like the comments don't
match the code.
According to the code, the following queryStrings should return:
"SELECT Foo FROM Foo WHERE Foo.param1 = :value" TRUE (index == -1, Should
have been false, right?)
"SELECT Foo FROM Foo WHERE Foo.param1 = ?" FALSE (found index is last char,
Should have been true, right?)
"SELECT Foo FROM Foo WHERE Foo.param1 = ?1" TRUE (found index is followed by a
digit)
I noticed this problem when I tried using a query similar to the first (by name) but was
trying to set the parameters by index (similar to Fabrice Daugan). It looks like it would
work correctly if the return values were swapped for the first two cases.
private boolean isPositionalParameter() {
256 if (isPositional == null) {
257 //compute it
258 String queryString = query.getQueryString();
259 int index = queryString.indexOf( '?' );
260 //there is a ? and the following char is a digit
261 if (index == -1) {
262 //no ?
263 isPositional = true;
264 }
265 else if ( index == queryString.length() - 1 ) {
266 // "... ?"
267 isPositional = false;
268 }
269 else {
270 isPositional = Character.isDigit( queryString.charAt( index + 1 ) );
271 }
272 }
273 return isPositional;
274 }
275
Query#setParameter(int position, Object value) wrong implementation
-------------------------------------------------------------------
Key: EJB-361
URL:
http://opensource.atlassian.com/projects/hibernate/browse/EJB-361
Project: Hibernate Entity Manager
Issue Type: Bug
Components: EntityManager
Affects Versions: 3.3.2.GA
Reporter: Fabrice Daugan
Original Estimate: 2 hours
Remaining Estimate: 2 hours
The Hibernate JPA javax.persistence.Query#setParameter(int position, Object value)
implementation does not suit to the JPA specicafication.
Indeed, the actual integer passed to the operation is converted to String by Hibernate
and then used to find the named parameter.
Please have a look to the folowing stack trace :
java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.IllegalArgumentException:
org.hibernate.QueryParameterException: could not locate named parameter [1]
at org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:185)
at org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:240)
at org.springframework.orm.jpa.JpaTemplate$9.doInJpa(JpaTemplate.java:316)
To repoduce this error :
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira