I am getting an unexpected error in my JPA repository. Spring cannot create repo bean because of an exception related to JPA.
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'fooRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Could not create query metamodel for method public abstract com.xxxxx.entities.Foo com.xxxxx.repositories.FooRepository.findByCourierId(java.lang.Long)!
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
Caused by: java.lang.IllegalArgumentException: Could not create query metamodel for method public abstract com.xxxxx.entities.Foo com.xxxxx.repositories.FooRepository.findByCourierId(java.lang.Long)!
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:97)
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:206)
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:73)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:367)
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:190)
Caused by: java.lang.IllegalArgumentException: Unable to locate Attribute with the the given name [courierId] on this ManagedType [com.xxxxx.core.models.XXXObject]
Code for my repo is as follows :
public interface FooRepository extends XXXRepository<Foo> {
Foo findByCourierId(Long courierId);
@Query("SELECT CA " +
"FROM Foo CA " +
"WHERE CA.courier.id IN (?1)")
List<Foo> findByCourierIds(List<Long> courierIds);
}
Now the weird thing is that it error displays for the first query which was working perfectly find before added the second method, if i remove the second query, the code works fine.
Code for the entity goes something like this
@Entity
public class Foo extends XXXObject {
@OneToOne
@JoinColumn(name = "courier_id")
private Courier courier;
....
Instead of
public interface FooRepository extends XXXRepository<Foo> {
Can you use JPARepository
public interface FooRepository extends JpaRepository<Foo, Long> {
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.