gpt4 book ai didi

java - 使用@Query时将 'nativeQuery'设置为 'true'有什么好处?

转载 作者:行者123 更新时间:2023-12-02 01:13:23 25 4
gpt4 key购买 nike

Spring Data 的文档 mentions the nativeQuery property of the @Query annotation ,但没有提及优点:

The @Query annotation allows for running native queries by setting the nativeQuery flag to true, as shown in the following example:

public interface UserRepository extends JpaRepository<User, Long> {

@Query(value = "SELECT * FROM USERS WHERE EMAIL_ADDRESS = ?1", nativeQuery = true)
User findByEmailAddress(String emailAddress);
}

我找不到任何有关何时以及为何执行此操作的文档。使用nativeQuery = true有什么好处?

最佳答案

@Query注释具有nativeQuery = true参数时,查询将不会被解析为JPQL。这可能会带来更好的性能,但当您使用 MySQL 方言创建查询并尝试在 MS SQL 服务器上执行它们时,就会很危险。

关于java - 使用@Query时将 'nativeQuery'设置为 'true'有什么好处?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59032939/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com