0
我正在使用jpa連接到mysql。當我使用的查詢表數據庫如下:錯誤查詢jpa彈簧啓動
public interface CommentRepository extends JpaRepository<Comment1, Integer>{
\t @Query(value = "SELECT * FROM comment1 WHERE contribution_id=:contributionId",nativeQuery = true)
\t List<Comment1> findByContributionId(@Param("contributionId") String contributionId);
}
package com.example;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.List;
import javax.annotation.Generated;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
/**
* Comment1エンティティクラス
*
*/
@Entity
public class Comment1 implements Serializable {
\t private static final long serialVersionUID = 1L;
\t /** commentIdプロパティ */
\t @Id
\t @GeneratedValue(strategy = GenerationType.IDENTITY)
\t @Column(name = "comment_id", precision = 11, nullable = false, unique = true)
\t public Integer commentId;
\t /** contributionIdプロパティ */
\t @Column(name = "contribution_id", precision = 20, nullable = false, unique = false)
\t public Integer contributionId;
\t /** userIdプロパティ */
\t @Column(precision = 11, nullable = false, unique = false)
\t public Integer userId;
\t /** commentプロパティ */
\t @Column(length = 2000, nullable = true, unique = false)
\t public String comment;
\t /** photoIdプロパティ */
\t @Column(precision = 11, nullable = true, unique = true)
\t public Integer photoId;
\t /** stampIdプロパティ */
\t @Column(precision = 11, nullable = true, unique = true)
\t public Integer stampId;
\t /** likeCountプロパティ */
\t @Column(precision = 11, nullable = false, unique = false)
\t public Integer likeCount;
\t /** updateDateプロパティ */
\t @Column(nullable = true, unique = false)
\t public Timestamp updateDate;
\t /** createDateプロパティ */
\t @Column(nullable = false, unique = false)
\t public Timestamp createDate;
\t /** deleteFlgプロパティ */
\t @Column(precision = 11, nullable = false, unique = false)
\t public Integer deleteFlg;
\t // public List<Stamp1> stamp1List;
\t /** stampPlaceプロパティ */
\t @Column(precision = 11, nullable = false, unique = false)
\t public Integer stampPlace;
}
我控制器交易
package com.example;
import java.util.List;
import javax.transaction.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
@Transactional
public class ServiceComment {
\t @Autowired
\t CommentRepository commentRepository;
\t
\t public String findByFb(String contributionId){
\t \t List<Comment1> datas = commentRepository.findByContributionId(contributionId);
\t \t if (datas.size() != 0){
\t \t \t Comment1 data = datas.get(0);
\t \t \t return "found " + datas.size()+ "recore";
\t \t \t
\t \t }else return "not found recore";
\t \t
\t }
}