Spring JPA Repository - jsonObject의 연산자 SIMPLE_PROPERTY에는 스칼라 인수가 필요합니다.
JPA 쿼리를 사용하여 Spring Boot Applications를 업데이트하고 있습니다.특정 종류의 쿼리를 제외하고 모든 것이 정상적으로 동작합니다).findByJsonNode이전 버전에서는 정상적으로 동작했지만 업그레이드 후 콩이 생성되지 않습니다.
스프링 부트까지 정상적으로 동작했다.2.1.4.RELEASE및 봄 클라우드 버전Greenwich.SR1단, Spring Boot로 업그레이드 시2.2.4.RELEASE및 봄 클라우드 버전Hoxton.RELEASE, 봄은 내 저장소 bean을 만들 수 없습니다.
Caused by: java.lang.IllegalStateException: Operator SIMPLE_PROPERTY on searchDto requires a scalar argument, found class com.fasterxml.jackson.databind.JsonNode in method public abstract se.company.search.Search se.company.search.SearchRepository.findFirstBySearchDto(com.fasterxml.jackson.databind.JsonNode).
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.throwExceptionOnArgumentMismatch(PartTreeJpaQuery.java:171)
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.validate(PartTreeJpaQuery.java:147)
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:90)
... 73 common frames omitted.
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.throwExceptionOnArgumentMismatch(PartTreeJpaQuery.java:171) ~[spring-data-jpa-2.2.4.RELEASE.jar:2.2.4.RELEASE]
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.validate(PartTreeJpaQuery.java:147) ~[spring-data-jpa-2.2.4.RELEASE.jar:2.2.4.RELEASE]
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:90) ~[spring-data-jpa-2.2.4.RELEASE.jar:2.2.4.RELEASE]
... 74 common frames omitted
저장소 클래스는 다음과 같습니다.
@Repository
public interface SearchRepository extends PagingAndSortingRepository<Search, String> {
Search findFirstBySearchDto(JsonNode searchDto);
}
독립체
/**
* Entity for saving as search
*
* Users can save searches and every search will be stored in history for reference
*/
@Slf4j
@Data
@Entity(name = "search")
@Table(name = "tt_searches", indexes = {
@Index(columnList = "searchDto", name = "searchdto_hidx")
})
@TypeDef(
name = "json-node",
typeClass = JsonNodeStringType.class
)
@EqualsAndHashCode(exclude = { "id", "savedSearches", "searchHistory" })
public class Search {
public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper().findAndRegisterModules();
public Search() {
}
public Search(SearchDto searchDto, List<SavedSearch> savedSearches, List<SearchHistory> searchHistory) {
this.searchDto = OBJECT_MAPPER.valueToTree(searchDto);
this.savedSearches = savedSearches;
this.searchHistory = searchHistory;
}
public Search(JsonNode searchDto, List<SavedSearch> savedSearches, List<SearchHistory> searchHistory) {
this.searchDto = searchDto;
this.savedSearches = savedSearches;
this.searchHistory = searchHistory;
}
@Id
@Column(columnDefinition = "CHAR(36)")
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid2")
private String id;
@Type(type = "json-node")
@Column(columnDefinition = "VARCHAR(2000)", unique = true)
private JsonNode searchDto;
@OneToMany(mappedBy = "search", fetch = FetchType.LAZY)
@OrderBy("name DESC")
@JsonIgnore
private List<SavedSearch> savedSearches;
@OneToMany(mappedBy = "search", fetch = FetchType.LAZY)
@OrderBy("timestamp DESC")
@JsonIgnore
private List<SearchHistory> searchHistory;
public SearchDto getSearchDto() {
try {
return OBJECT_MAPPER.treeToValue(searchDto, SearchDto.class);
} catch (JsonProcessingException e) {
log.error("Could not convert JsonNode to SearchDto when retrieving data from entity: {}", this.id);
return null;
}
}
public void setSearchDto(SearchDto searchDto) {
this.searchDto = OBJECT_MAPPER.valueToTree(searchDto);
}
}
나는 이 같은 문제를 만났다.저는 그 끝에 In을 붙여서 메서드 이름을 바꾸면서 작업을 했습니다.
예를 들어 다음과 같습니다.
findAllByTagsIn(java.util.Set)
다음 URL의 "supported keywords inside method names" 표를 참조하십시오.https://docs.spring.io/spring-data/jpa/docs/current/reference/html/ # jpa . supported keywords - bywords - by
열 값 목록을 술어로 사용하여 엔티티를 검색하는 경우 열 이름 끝에 "In" 절을 사용해야 합니다.에러블을 사용할 수 있습니다.
List<Entity> findAllByEntityColumnIn(Iterable<Long> EntityColumns);
주의: 제 프로젝트에서 100% 테스트되었습니다.
저장소를 사용하고 Set의 일종인 매개 변수를 기반으로 목록을 가져오려는 경우 쿼리 작성에 주의해야 합니다.내 경우:
findAllBySchoolId(Set<Long> schoolIds) // wrong
findAllBySchoolIdIn(Set<Long> schoolIds) // correct
사용자 크레딧 : 8569305 (smythie)!
언급URL : https://stackoverflow.com/questions/60397201/spring-jpa-repository-operator-simple-property-on-jsonobject-requires-a-scalar
'programing' 카테고리의 다른 글
| 순환 참조가 있는 경우에도 DOM 노드를 JSON으로 시리얼화하려면 어떻게 해야 합니까? (0) | 2023.03.06 |
|---|---|
| 스프링 부트 - Environment @Autowired가 Null Pointer를 슬로우합니다.예외. (0) | 2023.03.06 |
| Mongoose에서 고유한 값을 쿼리하려면 어떻게 해야 합니까? (0) | 2023.03.06 |
| jQuery.getJSON - 접근컨트롤-허용-발신원 문제 (0) | 2023.03.06 |
| JSON의 이스케이프 문자 대체 (0) | 2023.03.06 |