Reputation: 2816
The application is built with JHipster/Spring Boot and PostgreSQL as its repository. Based on this article, I have a custom UserType class and a SQL dialect class as the following
public class CustomPostgreSQLDialect extends PostgreSQL94Dialect {
public CustomPostgreSQLDialect() {
this.registerColumnType(Types.JAVA_OBJECT, "jsonb");
}
}
And I have its configuration in application.xml file as
spring:
...
jpa:
open-in-view: false
hibernate:
ddl-auto: none
naming:
physical-strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
implicit-strategy: org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
properties:
hibernate.dialect: com.abc.customdatatypes.usertype.CustomPostgreSQLDialect
For an integration test,
@Test
@Transactional
public void createProduct() throws Exception {
int databaseSizeBeforeCreate = productRepository.findAll().size();
// Create the Product
restProductMockMvc.perform(post("/api/products")
.contentType(TestUtil.APPLICATION_JSON_UTF8)
.content(TestUtil.convertObjectToJsonBytes(product)))
.andExpect(status().isCreated());
// Validate the Product in the database
List<Product> productList = productRepository.findAll();
assertThat(productList).hasSize(databaseSizeBeforeCreate + 1);
Product testProduct = productList.get(productList.size() - 1);
assertThat(testProduct.getBrand()).isEqualTo(DEFAULT_BRAND);
assertThat(testProduct.getName()).isEqualTo(DEFAULT_NAME);
assertThat(testProduct.getKeywords()).isEqualTo(DEFAULT_KEYWORDS);
assertThat(testProduct.getSpecs()).isEqualTo(DEFAULT_SPECS);
assertThat(testProduct.getSeason()).isEqualTo(DEFAULT_SEASON);
// Validate the Product in Elasticsearch
verify(mockProductSearchRepository, times(1)).save(testProduct);
}
I get the following error:
Caused by: org.hibernate.MappingException: No Dialect mapping for JDBC type: 2000
at org.hibernate.dialect.TypeNames.get(TypeNames.java:70)
at org.hibernate.dialect.TypeNames.get(TypeNames.java:101)
at org.hibernate.dialect.Dialect.getTypeName(Dialect.java:346)
at org.hibernate.mapping.Column.getSqlType(Column.java:231)
at org.hibernate.tool.schema.internal.AbstractSchemaValidator.validateColumnType(AbstractSchemaValidator.java:156)
at org.hibernate.tool.schema.internal.AbstractSchemaValidator.validateTable(AbstractSchemaValidator.java:143)
at org.hibernate.tool.schema.internal.GroupedSchemaValidatorImpl.validateTables(GroupedSchemaValidatorImpl.java:42)
at org.hibernate.tool.schema.internal.AbstractSchemaValidator.performValidation(AbstractSchemaValidator.java:89)
at org.hibernate.tool.schema.internal.AbstractSchemaValidator.doValidation(AbstractSchemaValidator.java:68)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:191)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:72)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:312)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:460)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:892)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:57)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:390)
... 68 more
It seems that the SQL dialect configuration has no effect. I add the same line of configuration to application-dev.yml as well as application-prod.xml without a luck.
Is a way to find out whether the SQL dialect configuration has an effect or not?
Upvotes: 2
Views: 12395
Reputation: 32535
Correct config key is
spring.jpa.properties.hibernate.dialect
while yours effectively is
spring.jpa.properties.dialect
It would be easier for you if you would use properties
file instead of yaml
Upvotes: 3