I have the following JPA method:
@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();
}
It is throwing the following error message:
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]
This is from the Spring petclinic sample application, so all relevant code is at this link, including the database definition. I am using the hsqldb and jpa, the findByPetType() method above is something I wrote, which is not in the sample application.
Can anyone show me how to fix the code so that it does not produce this error message?
EDIT:
I followed Alex's advice and changed pet.type_id to pet.type. Now it is giving me the following error message (the value of typeID is set to 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]
SECOND EDIT:
I made Sergi Almar's suggestion, and now it is throwing the following error:
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]
I checked, and the calling code initiates typeID as "Integer typeID = 1;" So I am not sure why it is not seeing an integer here.
Change pet.type_id
to pet.type
. You have to use entity's mapping properties (but not column names) in HQL
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With