我对 spring data JPA 命名方法 findAllBy 有问题...这是我的实体:@Id@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")@SequenceGenerator(name = "sequenceGenerator")private Long id;@Column(name = "entity_id")private Long entityId;@Column(name = "entity_name")private String entityName;@Column(name = "user_id")private Long userId;@Column(name = "rating")private Double rating;@Column(name = "like")private Long like;@Column(name = "dislike")private Long dislike;@Column(name = "review_title")private String reviewTitle;@Lob@Column(name = "review_comment")private String reviewComment;@Column(name = "time")private ZonedDateTime time;@ManyToOneprivate RatingType type;与 getter 和 setter。这是 ratingServiceImpl 中使用 @Autowired ratingRepository 的方法调用:List<Rating> ratings = ratingRepository.findAllByEntityIdAndEntityName(entityId, entityName);和存储库:@Repositorypublic interface RatingRepository extends JpaRepository<Rating, Long>, JpaSpecificationExecutor<Rating> { List<Rating> findAllByEntityIdAndEntityName(Long entityId, String entityName); }依赖关系:<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> <version>1.5.10.RELEASE</version></dependency>
1 回答
holdtom
TA贡献1805条经验 获得超10个赞
创建 JPA 实体时,尽量不要使用 DB 保留字作为列名和变量。
我相信问题出在
@Column(name = "like") private Long like;
spring生成的SQL语句是:
... RATING0_.LIKE[*] AS LIKE5_48_,
可以更改列名称吗?
添加回答
举报
0/150
提交
取消