在运行springjpa的查询时,我得到了多个相同的条目
这是我的问题
@Query(value = "Select * FROM t1" +
" LEFT JOIN t2 im ON t1.id=im.id", nativeQuery = true)
public List<GetList> getList()
当在mysql上运行时,这个查询给了我正确的数据,但是在springjpa上它给了我重复的记录t2有多个t1的记录id这里是sql的结果
t2Id id
1 605
2 605
3 605
4 605
5 589
6 589
7 589
9 606
2
5
6
15
16
29
这是实体
@Entity
public class GetList {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", unique = true, nullable = false)
private Integer Id;
@Column(name = "t2Id ", unique=true,nullable=false)
private Integer t2Id ;
}
这是springjpa的结果
t2Id id
4 605
4 605
4 605
4 605
t2表数据和更多字段
t2Id id
1 605
2 605
3 605
4 605
5 589
6 589
7 589
9 606
2
5
6
15
16
29
t1数据
status id
Active 605
Active 589
Active 606
Active 2
Active 5
Active 6
Active 15
Active 16
Active 29
我试过很多东西,但都没用。任何解决办法都会有帮助
1条答案
按热度按时间8tntrjer1#
根据您的评论,这是一个dto,而不是jpa的托管实体。放弃注解并为每个属性添加getter/setter。
springdatajpa现在将它用作投影,而不是托管实体。