错误查询jpa spring boot

时间:2015-12-03 04:06:50

标签: spring spring-boot

我正在使用jpa连接到mysql。当我使用查询到表数据库时:

public interface CommentRepository  extends JpaRepository<Comment1, Integer>{
	@Query(value = "SELECT * FROM comment1 WHERE contribution_id=:contributionId",nativeQuery = true)
	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 {

	private static final long serialVersionUID = 1L;

	/** commentIdプロパティ */
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "comment_id", precision = 11, nullable = false, unique = true)
	public Integer commentId;

	/** contributionIdプロパティ */
	@Column(name = "contribution_id", precision = 20, nullable = false, unique = false)
	public Integer contributionId;

	/** userIdプロパティ */
	@Column(precision = 11, nullable = false, unique = false)
	public Integer userId;

	/** commentプロパティ */
	@Column(length = 2000, nullable = true, unique = false)
	public String comment;

	/** photoIdプロパティ */
	@Column(precision = 11, nullable = true, unique = true)
	public Integer photoId;

	/** stampIdプロパティ */
	@Column(precision = 11, nullable = true, unique = true)
	public Integer stampId;

	/** likeCountプロパティ */
	@Column(precision = 11, nullable = false, unique = false)
	public Integer likeCount;

	/** updateDateプロパティ */
	@Column(nullable = true, unique = false)
	public Timestamp updateDate;

	/** createDateプロパティ */
	@Column(nullable = false, unique = false)
	public Timestamp createDate;

	/** deleteFlgプロパティ */
	@Column(precision = 11, nullable = false, unique = false)
	public Integer deleteFlg;

	// public List<Stamp1> stamp1List;

	/** stampPlaceプロパティ */
	@Column(precision = 11, nullable = false, unique = false)
	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 {
	@Autowired
	CommentRepository commentRepository;
	
	public String findByFb(String contributionId){
		List<Comment1> datas = commentRepository.findByContributionId(contributionId);
		if (datas.size() != 0){
			Comment1 data = datas.get(0);
			return "found " + datas.size()+ "recore";
			
		}else  return "not found recore"; 
		
	}
}

我的问题是: 当前我的数据库表“Comment1”存在500行的数据。 colume“contribution_id”的值为1到2235659。 - 当我从值contrib_id查询1到918时 - &gt;查询成功 - 当我从919到2235659进行查询时,虽然它存在于表中,但它找不到任何行。我认为它与配置限制查询或任何问题有关 请帮我解决这个问题 非常感谢!!

1 个答案:

答案 0 :(得分:0)

更新: 我检查更多时间并找到与colume create_date相关的原因 如果创建日期&gt; 2015-06-24 15:47:52它无法查询真实。

enter image description here