我有一个实体类和存储库。在这里,我试图执行更新查询,但不工作。如何在本机查询中更新Lob列或在jpa查询中更新Lob列的任何其他解决方案。
@Entity
@Table(name = "comment")
public class Comment implements Serializable {
@Basic
@Lob
@Column(name="Article_COMMENT", columnDefinition="TEXT")
private String articleComment;
@Basic
@Column(name = "ID_ARTICLE")
private Long articleId;
}
@Repository
public interface commentRepository extends JpaRepository<Comment, Long> {
@Query(value = "UPDATE comment set articleComment=: articleComment WHERE articleId =: articleId", nativeQuery=true)
void updateComment(@Param("articleComment") String articleComment, @Param("articleId") Long articleId );
}
错误:
No results were returned by query.
JpaSystemException thrown with message: could not extract ResultSet; nested exception is org.hibernate.exception.GenericJDBCException: could not extract ResultSet
你的问题很模糊,所以我只能根据假设来回答。我想你想要更新你实体的articlecomment字段。您可以简单地使用JpaRepository的.save()方法。您的代码应该如下所示。这里我也假设你的articleId是你的实体类的唯一标识符。
@Entity
@Table(name = "comment")
public class Comment implements Serializable {
@Basic
@Lob
@Column(name="Article_COMMENT", columnDefinition="TEXT")
private String articleComment;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID_ARTICLE")
private Long articleId;
}
现在您的Id应该是唯一的,并且有一个@Id注释来在spring数据JPA中识别它。您不必在JPA存储库中添加任何代码。只需调用commentreposiitory .save(commentObject)方法。如果commentObject的ID为0然后一个新的评论将被创建。如果ID是一个正值,并且出现在您的表中,则该特定行将被更新而不是创建。
删除空格
UPDATE comment set articleComment=:articleComment WHERE articleId =:articleId