Spring Jpa table fields to increase support for the reserved words

For example: entity is

@Data
@Entity
@Table(name = "wx_user_storage")
@ToString
public class UserStorage implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;
    @Column(name = "key")
    private String key;

}

Dao class

public interface UserStorageDao extends JpaRepository<UserStorage, Long> {
    @Query("delete from UserStorage s where s.key = :key")
    @Modifying(clearAutomatically = true)
    @Transactional
    void clearUserKeys(@Param("key")String key);
}

Tests are:

@RunWith(SpringRunner.class)
@SpringBootTest(classes = {DianliApplication.class}, webEnvironment = SpringBootTest.WebEnvironment.MOCK)
public class UserStorageDaoTest {
    @Autowired
    private UserStorageDao userStorageDao;

    @Test
    public void test1() {
        userStorageDao.clearUserKeys("key");
    }
}

Add the following configuration in application.yaml

spring:
  jpa:
    properties:
      hibernate:
        globally_quoted_identifiers: true

Implementation of the results:

Hibernate: delete from `wx_user_storage` where `key`=?

Consistent with the proposed

Guess you like

Origin www.cnblogs.com/linphy/p/11274165.html