Open mmaryo opened 2 years ago
I did a little project Please find the attachment
This test
@SpringBootTest
class OneTest {
@Autowired
lateinit var exchangesRepository: ExchangesRepository
@Test
fun test() {
exchangesRepository.save(Exchanges(44, "66")).block()
val res = exchangesRepository.findAll().collectList().block()
println(res)
}
}
Throw this error
org.springframework.r2dbc.BadSqlGrammarException: execute; bad SQL grammar [UPDATE common."ExchangesCodesMapping" SET ExchangeCode = $1 WHERE common."ExchangesCodesMapping".ID = $2]; nested exception is io.r2dbc.spi.R2dbcBadGrammarException: [90079] [90079] Schema "COMMON" not found; SQL statement:
UPDATE common."ExchangesCodesMapping" SET ExchangeCode = $1 WHERE common."ExchangesCodesMapping".ID = $2 [90079-210]
Notice when I run the server to an existing database ExchangesRepository works very well It seems this code is unable to create the table at startup
It seems that is related to NamingStrategy How to override it ? I need to add a double quote and keep the case of string inside @Column("Name")
open class R2dbcConfiguration : AbstractR2dbcConfiguration() {
override fun connectionFactory(): ConnectionFactory {
throw ExecutionControl.NotImplementedException("No need")
}
override fun r2dbcMappingContext(namingStrategy: Optional<NamingStrategy>, r2dbcCustomConversions: R2dbcCustomConversions): R2dbcMappingContext {
val context = super.r2dbcMappingContext(namingStrategy, r2dbcCustomConversions)
context.isForceQuote = true
return context
}
}
spring.jpa.hibernate.ddl-auto
is completely unrelated to R2DBC
@mmaryo did you find any solution to this?
Below worked for me in a configuration class and below bean
@Bean public ConnectionFactoryInitializer connectionFactoryInitializer(ConnectionFactory connectionFactory) { ConnectionFactoryInitializer initializer = new ConnectionFactoryInitializer(); initializer.setConnectionFactory(connectionFactory); ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); populator.addScript(new ClassPathResource("schema.sql")); initializer.setDatabasePopulator(populator); return initializer; }
Then have you schema.sql in the resources folder
Finally add below in your application.properties or yml file
spring.resources.static-locations=classpath:/,classpath:/resources/
Hello
It looks like tables are not created Postgres stay empty
Even with
spring.jpa.hibernate.ddl-auto=create
This is my entity
And the repository
I use Spring Boot 3.0.0.M1, WebFlux, Jdk 17, Kotin, R2DBC
Do you have an idea? How to debug and find a solution?
EDIT Also I try to connect to H2 db
spring.r2dbc.url=r2dbc:h2:mem:///testdb
Connection is done But test end withThat means the table is not created at test startup