Buggy code:
public class QueryImpl implements Serializable , OpenJPAQuerySPI { private static final List EMPTY_LIST = new ArrayList ( 0 ) ; private static final Localizer _loc = Localizer . forPackage ( QueryImpl . class ) ; private DelegatingQuery _query ; private transient EntityManagerImpl _em ; private transient FetchPlan _fetch ; private Map < String , Object > _named ; private Map < Integer , Object > _positional ; private String _id ; public QueryImpl ( EntityManagerImpl em , RuntimeExceptionTranslator ret , Query query ) { } public QueryImpl ( EntityManagerImpl em , Query query ) { } public javax . persistence . Query getDelegate ( ) { } public OpenJPAEntityManager getEntityManager ( ) { } public String getLanguage ( ) { } public QueryOperationType getOperation ( ) { } public FetchPlan getFetchPlan ( ) { } public String getQueryString ( ) { } public boolean getIgnoreChanges ( ) { } public OpenJPAQuery setIgnoreChanges ( boolean ignore ) { } public OpenJPAQuery addFilterListener ( FilterListener listener ) { } public OpenJPAQuery removeFilterListener ( FilterListener listener ) { } public OpenJPAQuery addAggregateListener ( AggregateListener listener ) { } public OpenJPAQuery removeAggregateListener ( AggregateListener listener ) { } public Collection getCandidateCollection ( ) { } public OpenJPAQuery setCandidateCollection ( Collection coll ) { } public Class getResultClass ( ) { } public OpenJPAQuery setResultClass ( Class cls ) { } public boolean hasSubclasses ( ) { } public OpenJPAQuery setSubclasses ( boolean subs ) { } public int getFirstResult ( ) { } public OpenJPAQuery setFirstResult ( int startPosition ) { } public int getMaxResults ( ) { } public OpenJPAQuery setMaxResults ( int max ) { } public OpenJPAQuery compile ( ) { } private Object execute ( ) { if ( ( _query . getOperation ( ) ) != ( QueryOperations . OP_SELECT ) ) throw new InvalidStateException ( QueryImpl . _loc . get ( "not-select-query" , _query . getQueryString ( ) ) , null , null , false ) ; Map params = ( ( _positional ) != null ) ? _positional : _named ; Boolean registered = null ; PreparedQueryCache cache = _em . getPreparedQueryCache ( ) ; if ( cache != null ) { FetchConfiguration fetch = _query . getFetchConfiguration ( ) ; registered = cache . register ( _id , _query , fetch ) ; boolean alreadyCached = registered == null ; String lang = _query . getLanguage ( ) ; QueryStatistics stats = cache . getStatistics ( ) ; if ( alreadyCached && ( QueryLanguages . LANG_PREPARED_SQL . equals ( lang ) ) ) { PreparedQuery pq = _em . getPreparedQuery ( _id ) ; <START_BUG> params = pq . reparametrize ( params ) ; <END_BUG> stats . recordExecution ( pq . getOriginalQuery ( ) , alreadyCached ) ; } else { stats . recordExecution ( _query . getQueryString ( ) , alreadyCached ) ; } } Object result = _query . execute ( params ) ; if ( registered == ( Boolean . TRUE ) ) { cache . initialize ( _id , result ) ; } return result ; } public List getResultList ( ) { } public Object getSingleResult ( ) { } public int executeUpdate ( ) { } private static int asInt ( long l ) { } public FlushModeType getFlushMode ( ) { } public OpenJPAQuery setFlushMode ( FlushModeType flushMode ) { } public OpenJPAQuery setHint ( String key , Object value ) { } private void hintToSetter ( FetchPlan fetchPlan , String k , Object value ) { } public OpenJPAQuery setParameter ( int position , Calendar value , TemporalType t ) { } public OpenJPAQuery setParameter ( int position , Date value , TemporalType type ) { } Object convertTemporalType ( Date value , TemporalType type ) { } Object convertTemporalType ( Calendar value , TemporalType type ) { } public OpenJPAQuery setParameter ( int position , Object value ) { } public OpenJPAQuery setParameter ( String name , Calendar value , TemporalType type ) { } public OpenJPAQuery setParameter ( String name , Date value , TemporalType type ) { } public OpenJPAQuery setParameter ( String name , Object value ) { } public boolean isNative ( ) { } public boolean hasPositionalParameters ( ) { } public List getPositionalParameters ( ) { } public OpenJPAQuery setParameters ( Object ... params ) { } public Map < String , Object > getNamedParameters ( ) { } public OpenJPAQuery setParameters ( Map params ) { } public OpenJPAQuery closeAll ( ) { } public String [ ] getDataStoreActions ( Map params ) { } public int hashCode ( ) { } public boolean equals ( Object other ) { } public Map < String , Object > getHints ( ) { } public LockModeType getLockMode ( ) { } public Set < String > getSupportedHints ( ) { } public javax . persistence . Query setLockMode ( LockModeType lockMode ) { } public < T > T unwrap ( Class < T > cls ) { } private boolean invalidatePreparedQuery ( ) { } private void ignorePreparedQuery ( ) { } private void recordStatistics ( String query , boolean usingCachedVersion ) { } QueryImpl setId ( String id ) { } }

Fix:
params = pq . reparametrize ( params , _em . getBroker ( ) ) ;