0

I have an entity class and repository. Here I'm trying to execute update query but not working. How to update Lob column in native query or any another solution on jpa query to update Lob column.

@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 );

}

Error:

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

Priya
  • 3
  • 6

2 Answers2

1

Your question is very vague so I can answer on assumptions only. I think You want to update the articalComment field of your Entity. You can simply use .save() method of JpaRepository. Your code should be as follows. Here I am also assuming that your articleId is unique identifier to your entity class.

@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;
}

Now your Id should be unique and has a @Id Annotation to identify it inside spring data JPA. You don't have to add any code inside of your JPA repository. Simply call commentRepository.save(commentObject) method. If commentObject has an ID as 0 then a new Comment will be created. If the ID is a positive value and is present in your table that particular row will be updated not created.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Akash Jain
  • 316
  • 2
  • 10
0

remove the space try this way

UPDATE comment set articleComment=:articleComment WHERE articleId =:articleId
Procrastinator
  • 2,526
  • 30
  • 27
  • 36