Hibernate抛出这样的异常:
org.hibernate.QueryException: Expected positional parameter count: 2, actually detected 0
at org.hibernate.query.internal.QueryParameterBindingsImpl.verifyParametersBound(QueryParameterBindingsImpl.java:270)
at org.hibernate.query.internal.AbstractProducedQuery.beforeQuery(AbstractProducedQuery.java:1309)
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1408)
at org.hibernate.query.Query.getResultList(Query.java:146)
at pl.code.dao.PersonDAO.personExists(PersonDAO.java:59)
在这种方法中:
@Override
public boolean personExists(String firstName, String location) {
TypedQuery<Person> query = entityManager.createQuery("Select p FROM Person p WHERE p.firstName = ? and p.location = ?", Person.class);
List<Person> all = query.getResultList();
return all.size() > 0 ? true : false;
}
我正在使用Hibernate版本5.2.9.Final。 任何想法有什么不对?
答案 0 :(得分:0)
请使用以下示例来传递您的参数
<cfmail to="myemail"
from="myemail"
subject="myemail"
type="text">
Dear myemail
We, here at Bedrock, would like to thank you for joining.
Best wishes
Barney
</cfmail>
<cfoutput>
<p>Thank you test for registering.
We have just sent you an email.</p>
</cfoutput>
答案 1 :(得分:0)
我以这种方式传递参数:
@Override
public synchronized boolean addPerson(Person person){
if (personDAO.personExists(person.getFirstName(), person.getLocation())) {
return false;
} else {
personDAO.addPerson(person);
return true;
}
}
并在控制器中
@RequestMapping(value= "/person", method = RequestMethod.POST)
public ResponseEntity<Void> addPerson(@RequestBody Person person, UriComponentsBuilder builder) {
boolean flag = personService.addPerson(person);
if (flag == false) {
return new ResponseEntity<Void>(HttpStatus.CONFLICT);
}
HttpHeaders headers = new HttpHeaders();
headers.setLocation(builder.path("/person/{id}").buildAndExpand(person.getPid()).toUri());
return new ResponseEntity<Void>(headers, HttpStatus.CREATED);
}