[SPRING] org.springframework.data.mapping.PropertyReferenceException : 유형에 대한 속성 catch가 없습니다.
SPRINGorg.springframework.data.mapping.PropertyReferenceException : 유형에 대한 속성 catch가 없습니다.
스프링 데이터 저장소에 문제가 있습니다.
배포 할 때 Spring Data가 동적으로 메서드를 파생하려고 시도하지만 해당 엔터티에서 해당 속성을 찾을 수 없기 때문에 예외가 발생합니다.
이 문제없이 사용자 지정 리포지토리에 사용자 지정 메서드를 넣을 수 있습니까?
다음은 관련된 구성 요소입니다.
LocaleJpaRepositoryCustom에는 메소드가 있습니다.
List<String> catchLanguagesCombinations() throws DAOSystemException;
(LanguagesCombinations는 LocaleJpaImpl의 속성이 아닙니다. 그 동기는 Custom Repository에 있습니다.)
이 예외 :
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property languages found for type com.engine.i18n.domain.LocaleJpaImpl
at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:74)
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:326)
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:352)
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:306)
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:270)
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:244)
at org.springframework.data.repository.query.parser.Part.<init>(Part.java:73)
at org.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:180)
at org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:260)
at org.springframework.data.repository.query.parser.PartTree$Predicate.<init>(PartTree.java:240)
at org.springframework.data.repository.query.parser.PartTree.<init>(PartTree.java:68)
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:57)
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:90)
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:162)
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:68)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:280)
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:148)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:125)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:41)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:142)
... 33 more
다음은 관련 코드입니다.
1. LocaleJpaImpl :
import java.io.Serializable;
import javax.persistence.AttributeOverride;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import com.jpa.BaseEntityJpaSupport;
@Entity
@Table(name = "LOCALE")
@XmlRootElement
@AttributeOverride(name="id", column=@Column(name="LOCALE_ID"))
@NamedQueries({
@NamedQuery(name = "Locale.findAll", query = "FROM LocaleJpaImpl l"),
@NamedQuery(name = "Locale.findByLocaleId", query = "FROM LocaleJpaImpl l WHERE l.localeId = :localeId"),
@NamedQuery(name = "Locale.findByLanguageCode", query = "FROM LocaleJpaImpl l WHERE l.languageCode = :languageCode")
public class LocaleJpaImpl extends BaseEntityJpaSupport implements Serializable {
private static final long serialVersionUID = 1L;
//@Id
//@Column(name = "LOCALE_ID")
@Basic(optional = false)
@NotNull
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer localeId;
@Size(max = 2)
@Column(name = "LANGUAGE_CODE")
private String languageCode;
public LocaleJpaImpl(Integer localeId) { this.localeId = localeId; }
public int getLocaleId() { return localeId; }
public void setLocaleId(Integer localeId) { this.localeId = localeId; }
public String getLanguageCode() { return languageCode; }
public void setLanguageCode(String languageCode) { this.languageCode = languageCode; }
}
3. 인터페이스 LocaleJpaRepository
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import com.engine.i18n.domain.LocaleJpaImpl;
public interface LocaleJpaRepository extends JpaRepository<LocaleJpaImpl, Long>, LocaleJpaRepositoryCustom {
@Query("FROM LocaleJpaImpl L WHERE L.languageCode = :languageCode")
List<LocaleJpaImpl> findLocaleByLanguageCode(@Param("languageCode") String languageCode);
}
4. 인터페이스 LocaleJpaRepositoryCustom
import java.util.List;
import com.util.DAOSystemException;
public interface LocaleJpaRepositoryCustom {
List<String> catchLanguagesCombinations() throws DAOSystemException;
}
5. LocaleJpaRepositoryImplemented
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import com.util.DAOSystemException;
public class LocaleJpaRepositoryImplemented implements LocaleJpaRepositoryCustom {
@PersistenceContext(unitName = "contentEntityManagerFactory")
private EntityManager em;
@SuppressWarnings("unchecked")
@Override
public List<String> catchLanguagesCombinations() throws DAOSystemException {
return "result";
}
}
해결법
-
==============================
1.이런 문제가 생겼고 실수는 맞춤 저장소 클래스의 이름이었습니다.
이런 문제가 생겼고 실수는 맞춤 저장소 클래스의 이름이었습니다.
jpa 저장소 인터페이스의 이름이 LocaleJpaRepository 인 경우 새 사용자 정의 인터페이스의 이름은 LocaleJpaRepositoryCustom 여야하지만 메서드에서 재정의하는 클래스의 이름은 다음과 같이 LocaleJpaRepositoryImpl로 지정해야합니다.
public class LocalJpaRepositoryImpl implements LocalJpaRepositoryCustom{ @Override public void customMethod(){....} }
기본적으로 사용자 인터페이스의 구현 클래스는 'Impl'키워드로 끝나는 저장소 인터페이스 (JPARepository)의 이름으로 시작해야합니다.
-
==============================
2.사용자 저장소 구현 클래스 이름은 Impl로 JPARepositry를 확장하는 인터페이스 이름이어야합니다.
사용자 저장소 구현 클래스 이름은 Impl로 JPARepositry를 확장하는 인터페이스 이름이어야합니다.
from https://stackoverflow.com/questions/20777785/org-springframework-data-mapping-propertyreferenceexception-no-property-catch-f by cc-by-sa and MIT license
'SPRING' 카테고리의 다른 글
[SPRING] json 수신 및 deserialize 같이 봄 mvc 컨트롤러에서 개체 목록 (0) | 2019.01.10 |
---|---|
[SPRING] Spring 3.0에서 다중 선택 MVC (0) | 2019.01.10 |
[SPRING] Spring Data JPA로 사용자 정의 저장소를 만들려고 시도 할 때 유형 오류에 대한 속성을 찾을 수 없습니다 (0) | 2019.01.10 |
[SPRING] Spring Data JPA Repository에서 save () 후에 반환 된 인스턴스를 사용해야하는 이유는 무엇입니까? (0) | 2019.01.10 |
[SPRING] Spring 데이터 REST 커스텀 질의 통합 (0) | 2019.01.10 |