2
我寫了下面的查詢,並且在「device」和「account」之間有一個m:n關係,但是Native Query仍然返回帶有Inner Join的結果!彈簧數據jpa find()沒有連接關係
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 = ?
其實我需要這個,因爲我不希望有帳戶[]在我的findAll只是findById
什麼也解決你的意思是它仍然返回Inner Join的結果? –
返回兩個表中的所有字段,更新問題... –
這是hibernate如何翻譯你的問題,所以這裏的問題在哪裏? –