[英]Hibernate Reserved keyword escaping not working
由於在休眠模型中使用MYSQL
保留關鍵字,我遇到以下錯誤。
java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'when, who, why) values ('ICL670A - Project Deliverable - HAQ 1 - FDA-IR', null, ' at line 1
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120) ~[mysql-connector-java-8.0.15.jar:8.0.15]
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) ~[mysql-connector-java-8.0.15.jar:8.0.15]
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) ~[mysql-connector-java-8.0.15.jar:8.0.15]
at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:970) ~[mysql-connector-java-8.0.15.jar:8.0.15]
at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1109) ~[mysql-connector-java-8.0.15.jar:8.0.15]
at
我在application.properties
文件中設置了以下屬性,它以前可以工作,但現在不起作用,我無法弄清楚原因。
spring.jpa.properties.hibernate.globally_quoted_identifiers=true
現在我必須在我的模型定義中手動轉義列才能工作。
@Column(name = "`who`")
private String who;
@Column(name = "`when`")
private Date when;
@Column(name = "`why`")
private String why;
我怎樣才能進一步調試呢? 我怎樣才能確保這個財產被接受?
我們在 Spring Boot 項目中使用了多個數據庫連接。 所以所有的hibernate屬性都需要在DataSourceConfigurationFile
進行配置
@Primary
@Bean
public LocalContainerEntityManagerFactoryBean idotdbEntityManager() {
final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(idotdbDataSource());
em.setPackagesToScan("com.novartis.idot.model");
final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
final HashMap<String, Object> properties = new HashMap<>();
properties.put("hibernate.physical_naming_strategy", SpringPhysicalNamingStrategy.class.getName());
properties.put("hibernate.implicit_naming_strategy", SpringImplicitNamingStrategy.class.getName());
properties.put("hibernate.hbm2ddl.auto", env.getProperty("spring.hibernate.ddl-auto"));
properties.put("hibernate.dialect", env.getProperty("spring.hibernate.dialect"));
properties.put("hibernate.globally_quoted_identifiers", env.getProperty("spring.jpa.properties.hibernate.globally_quoted_identifiers"));
properties.put("hibernate.id.new_generator_mappings", env.getProperty("spring.jpa.properties.hibernate.id.new_generator_mappings"));
em.setJpaPropertyMap(properties);
return em;
}
@Bean
@Primary
@ConfigurationProperties(prefix="spring.datasource")
public DataSourceProperties idotdbDataSourceProperties() {
return new DataSourceProperties();
}
@Bean
@Primary
@ConfigurationProperties(prefix="spring.datasource")
public DataSource idotdbDataSource() {
return idotdbDataSourceProperties().initializeDataSourceBuilder().build();
}
@Primary
@Bean
public PlatformTransactionManager idotdbTransactionManager() {
final JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(idotdbEntityManager().getObject());
return transactionManager;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.