我编写了以下查询,“device”和“account”之间存在m:n关系,但使用Native Query,它仍然会返回带有Inner Join的结果!
public interface DeviceRepository extends JpaRepository<Device, Long> {
@Query(value = "select device.* from device #pageable",
countQuery = "select count(*) from device",
nativeQuery = true)
Page<Device> findByNative(Pageable peagble);
}
它返回所有两个表字段! (这是Hibernate生成的查询)
SELECT
accounts0_.device_id AS device_i1_2_0_,
accounts0_.account_id AS account_2_2_0_,
account1_.id AS id1_0_1_,
account1_.broker_id AS broker_i2_0_1_,
account1_.is_deleted AS is_delet3_0_1_,
account1_.user_id AS user_id4_0_1_
FROM
device_account accounts0_
INNER JOIN
account account1_ ON accounts0_.account_id = account1_.id
WHERE
accounts0_.device_id = ?
其实我需要这个,因为我不想在findById中的findAll中有帐户[]
答案 0 :(得分:1)
使用@SqlResultSetMapping解决