数据JPA。按示例查询。无法使用Long值进行搜索

时间:2018-04-07 09:21:29

标签: java spring spring-data-jpa query-by-example

我有一个实体产品

@Entity
@Table(name = "Products")
public class ProductEntity implements Serializable{
    @Id
    @GenericGenerator(name = "generator", strategy = "increment")
    @GeneratedValue(strategy=GenerationType.AUTO)
    private Long id;
    @Column(name = "model", nullable = false)
    private String model;
    //setters and getters
}

以下是我尝试按示例查询的方式:

ProductEntity product = new ProductEntity();
product.setId(productId);
Example<ProductEntity> ex = Example.of(product);
Page<ProductEntity> pages = productRepository.findAll(ex, page);

但是我得到PostgreSQL错误: PSQLException:错误:语法错误在或附近&#34; L&#34;。

此处创建的查询:

Hibernate: select productent0_.id as id1_13_, productent0_.brand_id as brand_id9_13_, productent0_.imgPath as imgPath2_13_, productent0_.model as model3_13_, productent0_.numberOfEvaluation as numberOf4_13_, productent0_.priceBuy as priceBuy5_13_, productent0_.priceSell as priceSel6_13_, productent0_.rating as rating7_13_, productent0_.sumOfEvaluation as sumOfEva8_13_, productent0_.type_id as type_id10_13_ from Products productent0_ where (productent0_.id=1L ) limit ?

systax错误在这里:

where (productent0_.id=1L )

它增加了&#39; L&#39;长值的字符。那么,我该如何解决这个问题?

更新: 有什么问题?仍然无法解决这个问题。

更新:我的存储库:

public interface CrudProductRepository extends JpaRepository<ProductEntity, Long>{
}

JpaRepository的包:

import org.springframework.data.jpa.repository.JpaRepository;

0 个答案:

没有答案