public interface StudentRepo extends JpaRepository<Student, Integer> {
@Query(value = "SELECT Name FROM STUDENT WHERE UNIQID=?", nativeQuery = true)
public abstract _______ getStudentByUniqueKey(String uniqueKey);
}
这是什么返回类型?
答案 0 :(得分:1)
答案是 String ,您还需要考虑在您的Student实体中为CLOB放置以下注释:
@Column(name="name", columnDefinition="CLOB NOT NULL")
@Lob
private String name;
更新:
columnDefinition =“ ...”的值取决于您的数据库。例如。对于PostreSQL,它必须为columnDefinition="text"
而不是columnDefinition="clob"
答案 1 :(得分:0)
您的StudentRep必须如下所示:
public interface StudentRepo extends JpaRepository<Student, Integer> {
@Query(value = "SELECT name FROM Student WHERE uniqid=:uniqid", nativeQuery = true)
public String getStudentNameByUniqueKey(@Param("uniqid")String uniqueKey);
}
如果要获取Student对象:
@Query(value = "SELECT student FROM Student student WHERE student.uniqid=:uniqid", nativeQuery = true)
public Student findStudentByUniqueKey(@Param("uniqid")String uniqueKey);
有关更多详细信息,您可以检查official doc
答案 2 :(得分:0)
我遇到了同样的问题,正在寻找解决方案。对于Oracle DB(在12c版本中有效),我们可以使用内置函数将Clob转换为String。这是特定于该问题的代码
public interface StudentRepo extends JpaRepository<Student, Integer> {
@Query(value = "SELECT dbms_lob.substr(Name) FROM STUDENT WHERE UNIQID=?", nativeQuery = true)
public abstract String getStudentByUniqueKey(String uniqueKey);
}