I got "QueryException: JPA-style positional param was not an integral ordinal" I try to solve by the way others solve such as org.hibernate.QueryException: JPA-style positional param was not an integral ordinal but it still doesn't work.
I try to hardcode change form ?1 to some data that already have in the database and it works but after change to ?1 it gives an error again.
--- Before Hardcode (have Error) -- In Repository --
@Query(
value = "SELECT user_att_workshop.id, user_att_workshop.user_id, user_att_workshop.workshop_att_id, skill.skill_name, user_att_workshop.skill_score " +
"FROM user_att_workshop LEFT JOIN skill on user_att_workshop.skill_id = skill.id " +
"WHERE user_att_workshop.user_id = ?1 " +
"AND user_att_workshop.workshop_att_id = ?2;",
nativeQuery = true
)
public List<UserScoreByWorkshopAtt> findUserScoreByUserIdAndWorkshopId(int userId, int workshopId);
-- In Service --
public List<UserScoreByWorkshopAtt> findUserScoreByUserIdAndWorkshopIdtest(
int userId,
int workshopId) {
return
userScoreByWorkshopAttRepository.findUserScoreByUserIdAndWorkshopId(
userId,
workshopId
);
}
-- In controller --
List<UserScoreByWorkshopAtt> getUserScooreByUserId(
@PathVariable("user_id") int userId,
@PathVariable("workshop_id") int workshopId) {
return userScoreByWorkshopAttService.findUserScoreByUserIdAndWorkshopIdtest(
userId,
workshopId
);
}
--- After Hardcode (can run and have no error) -- In Repository --
@Query(value = "SELECT user_att_workshop.id, user_att_workshop.user_id, user_att_workshop.workshop_att_id, skill.skill_name, user_att_workshop.skill_score FROM user_att_workshop LEFT JOIN skill on user_att_workshop.skill_id = skill.id WHERE user_att_workshop.user_id = 5 AND user_att_workshop.workshop_att_id = 2;", nativeQuery = true)
public List<UserScoreByWorkshopAtt> findUserScoreByUserIdAndWorkshopId();
-- In Service --
public List<UserScoreByWorkshopAtt> findUserScoreByUserIdAndWorkshopIdtest() {
return userScoreByWorkshopAttRepository.findUserScoreByUserIdAndWorkshopId();
}
-- In controller --
List<UserScoreByWorkshopAtt> getUserScooreByUserId(@PathVariable("user_id") int userId,
@PathVariable("workshop_id") int workshopId) {
return userScoreByWorkshopAttService.findUserScoreByUserIdAndWorkshopIdtest();
}
Caused by: org.hibernate.QueryException: JPA-style positional param was not an integral ordinal at org.hibernate.engine.query.spi.ParameterParser.parse(ParameterParser.java:195) at org.hibernate.engine.query.spi.ParamLocationRecognizer.parseLocations(ParamLocationRecognizer.java:56) at org.hibernate.engine.query.internal.NativeQueryInterpreterStandardImpl.getParameterMetadata(NativeQueryInterpreterStandardImpl.java:30) at org.hibernate.engine.query.spi.QueryPlanCache.getSQLParameterMetadata(QueryPlanCache.java:128) at org.hibernate.internal.AbstractSharedSessionContract.getNativeQueryImplementor(AbstractSharedSessionContract.java:1000) ... 85 more