2015-12-03 150 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