這是失敗的:JPA的EntityManager的createQuery()錯誤
public List<TypeActionCommerciale> requestTypeActionCommercialeSansNip() throws PersistenceException {
Query query = createQuery("from TypeActionCommercialeImpl where type != :type1");
query.setParameter("type1", TypeActionCommercialeEnum.NIP);
return (List<TypeActionCommerciale>) query.list();
}
例外:
Hibernate: select typeaction0_.id as id1_102_, typeaction0_.libelle as libelle3_102_, typeaction0_.code as code4_102_, typeaction0_.type as type5_102_ from apex.typeActionCommerciale typeaction0_ where typeaction0_.type<>?
ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper.logExceptions(SqlExceptionHelper.java:129)
- No value specified for parameter 1 org.hibernate.exception.DataException: could not extract ResultSet at
我使用setProperties方法,但我有同樣的錯誤:
public List<TypeActionCommerciale> requestTypeActionCommercialeSansNip() throws PersistenceException {
Query query = createQuery("from TypeActionCommercialeImpl where type <> :type1");
final Map<String, Object> properties = new HashMap<>();
properties.put("type1", TypeActionCommercialeEnum.NIP);
query.setProperties(properties);
return (List<TypeActionCommerciale>) query.list();
}
嘿傢伙,也許你必須使用setProperties方法。試試! –
查詢很好。該問題指出參數1丟失。 TypeActionCommercialeEnum.NIP在哪裏?這就像它不在類路徑中一樣。你可以嘗試「從TypeActionCommercialeImpl類型!= TypeActionCommercialeEnum.NIP」(並刪除setParameter行),以查看你得到的錯誤 –
@IanMc錯誤:'org.hibernate.QueryException:無法解析路徑[TypeActionCommercialeEnum.NIP],意外標記[TypeActionCommercialeEnum] [來自com.metier.impl.TypeActionCommercialeImpl,其中類型!= TypeActionCommercialeEnum.NIP] ' – Mercer