我對 spring data JPA 命名方法 findAllBy 有問題...這是我的實(shí)體:@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 的方法調(diào)用:List<Rating> ratings = ratingRepository.findAllByEntityIdAndEntityName(entityId, entityName);和存儲(chǔ)庫:@Repositorypublic interface RatingRepository extends JpaRepository<Rating, Long>, JpaSpecificationExecutor<Rating> { List<Rating> findAllByEntityIdAndEntityName(Long entityId, String entityName); }依賴關(guān)系:<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> <version>1.5.10.RELEASE</version></dependency>
1 回答

holdtom
TA貢獻(xiàn)1805條經(jīng)驗(yàn) 獲得超10個(gè)贊
創(chuàng)建 JPA 實(shí)體時(shí),盡量不要使用 DB 保留字作為列名和變量。
我相信問題出在
@Column(name = "like") private Long like;
spring生成的SQL語句是:
... RATING0_.LIKE[*] AS LIKE5_48_,
可以更改列名稱嗎?
添加回答
舉報(bào)
0/150
提交
取消