2015-12-03 119 views
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 } 
 
}
我的问题是: 当前我的数据库表“Comment1”存在500行数据。与colume“contribution_id”的值为1到2235659. - 当我从value_id从1到918查询 - >查询成功 - 当我从919查询到2235659时,它找不到任何行,尽管它存在于表上。我认为它涉及配置极限查询或任何问题 请帮我解决这个问题 非常感谢你!

回答

0

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

enter image description here