2016-11-06 4 views
0

나는 엔티티 있습니다봄 데이터 기본 쿼리 흥미로운 버그

@Entity public class KnowledgeBase { 

    private Long id; 
    private String link; 
    private String content; 

    @Id 
    @SequenceGenerator(name = "knowledgebase_id_generator", sequenceName = "knowledgebase_id_sequence", allocationSize = 1) 
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "knowledgebase_id_generator") 
    public Long getId() { 
     return id; 
    } 

    public void setId(Long id) { 
     this.id = id; 
    } 

    public String getLink() { 
     return link; 
    } 

    public void setLink(String link) { 
     this.link = link; 
    } 

    public String getContent() { 
     return content; 
    } 

    public void setContent(String content) { 
     this.content = content; 
    } 
} 

을 그리고

@Repository public interface KnowledgeBaseRepository 
     extends AbstractRepository<KnowledgeBase, Long> { 

    @Query(value = "SELECT c.id as id,c.link as link, c.content as content" 
      + " from knowledgebase c where content=?1", nativeQuery = true) 
    List<KnowledgeBase> findRelevantRecords(String searchString); 
} 

where content=?1 

그냥이므로주의 해주십시오 스프링 데이터 저장소를 가지고 샘플, where 절은 테스트 용으로 다릅니다.

문제는이 저장소 방법을 실행하면 모든 것이 잘되지만 콘텐츠 열에는 많은 양의 텍스트가 포함되어 있기 때문에 지연로드를 원합니다. 그렇게하면 Long의 가치가 잘못되었다는 오류가 발생합니다. 따라서 내 사업체는 다음과 같습니다.

@Lob @Basic(fetch = LAZY) String content; 

내가 이것을 제거하면 모든 것이 잘됩니다. 콘텐츠 열이 매번로드되는 것을 방지하고 스프링 데이터 저장소 검색을 올바르게 수행하는 방법은 무엇입니까?

+0

내가 혼란 스러워요에 쿼리에서이 생성자 서명을 사용합니다. 어떤 버전에서 예외가 발생합니까? 실제 예외도 포함하십시오. –

답변

1

이 시도 : 만 필수 필드

public class KnowledgeBase{ 

//default constructor 
public KnowledgeBase(){} 

public KnowledgeBase(Long id,String link){ 
this.id=id; 
this.link=link; 
} 

} 

을 수락 할 개체의 생성자를 만들고 저장소

@Query(value = "SELECT new #{#entityName} (c.id as id,c.link as link) from #{#entityName} c " 
      + " from knowledgebase c where content=?1", nativeQuery = true) 
    List<KnowledgeBase> findRelevantRecordsWithoutContent(String searchString);