Sunday, April 28, 2024
HomeJavaHow you can repair "No Property Discovered for Kind class " Exception...

How you can repair “No Property Discovered for Kind class ” Exception in Spring Knowledge JPA [Solved]


org.springframework.information.mapping.PropertyReferenceException:
No property filterBy discovered for kind Person!

In response to the above query, the issue in right here is that your are creating FilterRepositoryImpl, however you’re utilizing it in UserRepository. It is advisable to create UserRepositoryImpl to make this work. 

So you should make the code as beneath to unravel this problem.

public interface UserRepositoryCustom {
Record<Person> filterBy(String function);
}

public class UserRepositoryImpl implements UserRepositoryCustom {
// your code
}

public interface UserRepository extends JpaRepository<Person, String>, UserRepositoryCustom {
// your precise code
}


That is should that the customMethod() within the CustomRepository can solely have parameters outlined which are both.
   1. Entity class identify - customMethod(Person consumer)
   2. Entity class attributes - customMethod(String firstName), right here firstName is an attribute of Person  Entity class.
You cannot have the customMethod(CustomCriteria standards), the factors class comprise the varied attributes which are used to assemble a dynamic delay.
instance -
 getStatusByCriteria(CustomCriteria standards) , CustomCriteria is an easy pojo annotated with @Element in order that spring identifies 

"No Property Discovered for Kind class  - Error 2

In right here, there's an utility to add information by the consumer and that is want to avoid wasting the bytes of information which is uploaded and needs to create {custom} repository for that. The code utilized in there are given beneath.

public interface MediaBytesRepository
{
public byte[] getBytes(Media media) throws IOException;
public void saveBytes(Media media, byte[] bytes) throws IOException;
public void appendBytes(Media media, byte[] bytes) throws IOException;
public void deleteBytes(Media media) throws IOException;
public boolean bytesExist(Media media) throws IOException;
}

Then supplied an implementation for this interface referred to as MediaBytesRepositoryIml. With this created the next interface.
public interface MediaRepository extends JpaRepository<Media, Lengthy>,
 MediaBytesRepository{
  // code
}
After beginning the server, the next error seem on the console.
SEVERE: Exception sending context initialized occasion to listener occasion of
 class org.springframework.internet.context.ContextLoaderListener
org.springframework.beans.manufacturing facility.BeanCreationException: Error creating bean with identify
'mediaRepository': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: Couldn't create question metamodel for technique public summary void com.foo.bar.core. media.MediaBytesRepository.saveBytes(com.foo.bar.core.media.Media,byte[]) throws java.io.IOException!
at org.springframework.beans.manufacturing facility.assist.FactoryBeanRegistrySupport .doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:
149)
.....
Attributable to: java.lang.IllegalArgumentException: Couldn't create question metamodel
for technique public summary void com.foo.bar.core.media.MediaBytesRepository .saveBytes(com.foo.bar.core.media.Media,byte[]) throws java.io.IOException!
at org.springframework.information.jpa.repository.question. JpaQueryLookupStrategy$CreateQueryLookupStrategy .resolveQuery(JpaQueryLookupStrategy.java:
92)
at org.springframework.information.jpa.repository.question .JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy .resolveQuery(JpaQueryLookupStrategy.java:
162)
at org.springframework.information.jpa.repository.question .JpaQueryLookupStrategy$AbstractQueryLookupStrategy .resolveQuery(JpaQueryLookupStrategy.java:
68)
at org.springframework.information.repository.core.assist .RepositoryFactorySupport$QueryExecutorMethodInterceptor .<
init>(RepositoryFactorySupport.java:280)
at org.springframework.information.repository.core.assist .RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:
148)
at org.springframework.information.repository.core.assist .RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:
125)
at org.springframework.information.repository.core.assist .RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:
41)
at org.springframework.beans.manufacturing facility.assist.FactoryBeanRegistrySupport .doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:
142)
...
20 extra
Attributable to: java.lang.IllegalArgumentException: No property save discovered for kind class com.foo.bar.core.media.Media
at org.springframework.information.mapping.PropertyPath.<
init>(PropertyPath.java:73)
at org.springframework.information.mapping.PropertyPath.<
init>(PropertyPath.java:92)
at org.springframework.information.mapping.PropertyPath.create(PropertyPath.java:
319)
at org.springframework.information.mapping.PropertyPath.create(PropertyPath.java:
333)
at org.springframework.information.mapping.PropertyPath.create(PropertyPath.java:
301)
at org.springframework.information.mapping.PropertyPath.from(PropertyPath.java:
265)
at org.springframework.information.mapping.PropertyPath.from(PropertyPath.java:
239)
at org.springframework.information.repository.question.parser.Half.<
init>(Half.java:70)
at org.springframework.information.repository.question.parser .PartTree$OrPart.<
init>(PartTree.java:180)
at org.springframework.information.repository.question.parser .PartTree$Predicate.buildTree(PartTree.java:
260)
at org.springframework.information.repository.question.parser .PartTree$Predicate.<
init>(PartTree.java:240)
at org.springframework.information.repository.question.parser .PartTree.<
init>(PartTree.java:68)
at org.springframework.information.jpa.repository.question. PartTreeJpaQuery.<
init>(PartTreeJpaQuery.java:57)

So how can we repair this error? Given beneath is learn how to clear up this error.

Right here additionally seem to have the naming conference error. It is advisable to rename the MediaBytesRepository to MediaRepositoryCustom and of trigger you want an implementation of MediaRepositoryCustom with the identify MediaRepositoryImpl
Let's have an one other error which could you get in spring information jpa.
Attempting to implement a {custom} Spring repository with the next interface.
public interface FilterRepositoryCustom {
Record<Person> filterBy(String function);
}

the implementation.
public class FilterRepositoryImpl implements FilterRepositoryCustom {
...
}
and the "primary" repository, extending my {custom} repository:
public interface UserRepository extends JpaRepository<Person, String>,
 FilterRepositoryCustom {
...
}
Once I run my utility, I get this error.
org.springframework.information.mapping.PropertyReferenceException:
 No property filterBy discovered for kind Person! 
The issue right here is that you're creating FilterRepositoryImpl however you're utilizing it in UserRepository. It is advisable to create UserRepositoryImpl to make this work.
Mainly,
public interface UserRepositoryCustom {
Record<Person> filterBy(String function);
}

public class UserRepositoryImpl implements UserRepositoryCustom {
...
}

public interface UserRepository extends JpaRepository<Person, String>, UserRepositoryCustom {
...
}


Spring Knowledge 2.x replace

In case you are dealing with problem on Spring Knowledge 2.x then it is best to do not forget that the naming expectations modified with Spring Knowledge 2.0. The implementation modified from the-final-repository-interface-name-with-an-additional-Impl-suffix to the-custom-interface-name-with-an-additional-Impl-suffix.




RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments