Cod*_*Med 4 java spring hibernate jpa
我有以下JPA方法:
@SuppressWarnings("unchecked")
public Collection<Owner> findByPetType(Integer typeID) {
Query query = this.em.createQuery("SELECT DISTINCT owner FROM Owner owner left join fetch owner.pets as pet WHERE pet.type_id LIKE :typeID");
query.setParameter("typeID", typeID + "%");
return query.getResultList();
}
Run Code Online (Sandbox Code Playgroud)
它抛出以下错误消息:
org.hibernate.QueryException: could not resolve property: type_id of:
org.springframework.samples.petclinic.model.Pet [SELECT DISTINCT owner FROM
org.springframework.samples.petclinic.model.Owner owner left join fetch owner.pets
as pet WHERE pet.type_id LIKE :typeID];
nested exception is java.lang.IllegalArgumentException:
org.hibernate.QueryException: could not resolve property: type_id of:
org.springframework.samples.petclinic.model.Pet [SELECT DISTINCT owner FROM
org.springframework.samples.petclinic.model.Owner owner left join fetch owner.pets
as pet WHERE pet.type_id LIKE :typeID]
Run Code Online (Sandbox Code Playgroud)
这来自Spring petclinic示例应用程序,因此所有相关代码都在此链接上,包括数据库定义。我正在使用hsqldb和jpa,上面的findByPetType()方法是我写的,但不在示例应用程序中。
谁能告诉我如何修复代码,以便它不会产生此错误消息?
编辑:
我遵循亚历克斯的建议,将pet.type_id更改为pet.type。现在,它给我以下错误消息(typeID的值设置为1):
Parameter value [1%] did not match expected type
[org.springframework.samples.petclinic.model.PetType]; nested exception is
java.lang.IllegalArgumentException: Parameter value [1%] did not match expected type
[org.springframework.samples.petclinic.model.PetType]
Run Code Online (Sandbox Code Playgroud)
第二编辑:
我提出了Sergi Almar的建议,现在它引发了以下错误:
Parameter value [1%] did not match expected type [java.lang.Integer]; nested exception
is java.lang.IllegalArgumentException: Parameter value [1%] did not match expected type
[java.lang.Integer]
Run Code Online (Sandbox Code Playgroud)
我检查了一下,调用代码将typeID初始化为“ Integer typeID = 1;”。因此,我不确定为什么在这里看不到整数。
| 归档时间: |
|
| 查看次数: |
12299 次 |
| 最近记录: |