java - spring data native query interesting bug with Lob column -
i have entity:
@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; } }
and have spring data repository
@repository public interface knowledgebaserepository extends abstractrepository<knowledgebase, long> { @query(value = "select c.id id,c.link link, c.content content" + " knowledgebase c content=?1", nativequery = true) list<knowledgebase> findrelevantrecords(string searchstring); }
please note
where content=?1
is sample, clause different testing.
the issue if run repository method, fine, content column contains large text amount, want lazy loaded. if error value wrong long: ''. entity is:
@lob @basic(fetch = lazy) string content;
if remove this, fine. how prevent content column being loaded every time , have spring data repository search properly?
try this: create constructor in entity accepts required fields
public class knowledgebase{ //default constructor public knowledgebase(){} public knowledgebase(long id,string link){ this.id=id; this.link=link; } }
and use constructor signature in query in repository
@query(value = "select new #{#entityname} (c.id id,c.link link) #{#entityname} c " + " knowledgebase c content=?1", nativequery = true) list<knowledgebase> findrelevantrecordswithoutcontent(string searchstring);
Comments
Post a Comment