public interface StudentRepo extends JpaRepository<Student, Integer> {
@Query(value = "SELECT Name FROM STUDENT WHERE UNIQID=?", nativeQuery = true)
public abstract _______ getStudentByUniqueKey(String uniqueKey);
}这里的返回类型是什么?
发布于 2018-11-24 13:19:54
答案是String,而且您还需要考虑在您的Student实体中为CLOB添加以下注释:
@Column(name="name", columnDefinition="CLOB NOT NULL")
@Lob
private String name;更新:
ColumnDefinition=的值“...”这取决于您的数据库。例如,对于PostreSQL,它必须是columnDefinition="text"而不是columnDefinition="clob"
发布于 2018-11-24 13:12:23
您的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);
}如果你想要获取学生对象:
@Query(value = "SELECT student FROM Student student WHERE student.uniqid=:uniqid", nativeQuery = true)
public Student findStudentByUniqueKey(@Param("uniqid")String uniqueKey);有关更多详细信息,请查看official doc
发布于 2020-07-22 01:42:43
我也在面对同样的问题,四处寻找解决方案。在Oracle DB的情况下(在12c版本的情况下工作),我们可以使用内置函数将Clob转换为字符串。以下是特定于该问题的代码
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);
}https://stackoverflow.com/questions/53455302
复制相似问题