8月 12, 2021

Making your SQL life easier, escaping field names

 First time had I faced with a reserved keyword issue : 'user'.


One option could be renaming table or column using @Table(name="something-else") or @Column, another option would be manually escape the word by "xx" [xx] ,etc depending on your SQL dialect.

Spring boot JPA has a flag to escape all field name automatically for you.


spring.jpa.properties.hibernate.globally_quoted_identifiers=true
 
 

https://docs.spring.io/spring-boot/docs/1.3.0.M2/reference/html/boot-features-sql.html 

 

 Also, while MSSQL uses [] for escaping, MySQL uses ``. 

Both are not interchangeable.

 

 
 

沒有留言:

張貼留言