0
我有一個實體:春天數據本地查詢有趣的錯誤與LOB列
@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;
如果我刪除這個,一切都很好。 如何防止每次加載內容列並正確地搜索彈簧數據存儲庫?
我很困惑在查詢中使用此構造函數簽名。哪個版本導致異常?也請包括實際的例外。 –