Related
I created a new spring boot project using the IntelliJ Idea's spring initializer and checked the Web/Spring reactive Web and the SQL/Spring data R2DBC dependencies.
I also added the the dependency to the R2DBC implementation for MySQL
<dependency>
<groupId>dev.miku</groupId>
<artifactId>r2dbc-mysql</artifactId>
<version>0.8.2.RELEASE</version>
</dependency>
and the java connector
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
Asking the version of the MySQL server from a console with
select version();
I get
8.0.17
The connection factory configuration is like this:
#Configuration
#RequiredArgsConstructor
public class R2dbcConfig extends AbstractR2dbcConfiguration {
#Bean
public ConnectionFactory connectionFactory() {
ConnectionFactoryOptions conf = ConnectionFactoryOptions.builder()
.option(DRIVER, "mysql")
.option(HOST, "the.db.url")
.option(PORT, 33066612)
.option(USER, "myUserName")
.option(PASSWORD, "myPassword")
.option(DATABASE, "aDbName")
.build();
return ConnectionFactories.find(conf);
}
}
Nevertheless, when I run the application I get the following exception
reactor.core.Exceptions$ErrorCallbackNotImplemented: org.springframework.dao.DataAccessResourceFailureException: Failed to obtain R2DBC Connection; nested exception is io.r2dbc.spi.R2dbcNonTransientResourceException: [1193] Unknown system variable 'tx_isolation'
Caused by: org.springframework.dao.DataAccessResourceFailureException: Failed to obtain R2DBC Connection; nested exception is io.r2dbc.spi.R2dbcNonTransientResourceException: [1193] Unknown system variable 'tx_isolation'
Answers to similar questions instructed the asker to update the version of the mysql:mysql-connector-java to 8.+, and according to IntelliJ the versión resolved by maven is 8.0.26.
Curiously, if I remove the connector dependency the result is exactly the same.
So, I debbuged the R2DBC implementation to find out what is happening and I discovered that during the handshake, the dev.miku.r2dbc.mysq.QueryFlow#initHandshake method receives a HandshakeRequest message whose headers tell that the server version is "5.5.30". And that causes the R2DBC implementation to use the old "tx_isolation" system variable name instead of the new "transaction_isolation".
Why?
What am I missing?
https://dev.mysql.com/doc/refman/8.0/en/mysql-nutshell.html says:
The tx_isolation and tx_read_only system variables have been removed. Use transaction_isolation and transaction_read_only instead.
You checked and discovered the server version is 8.0.17. This is more authoritative than the handshake headers message.
I recommend searching your classpath for any leftover jar files with old versions of the connector. You may have both version 8.0.26 of the connector and an older version that hasn't been updated to use the new option names.
Could you solved it? I found that R2dbc mysql driver doesn't get my MySql version, because it has a check of it to ask for tx_isolation or transaction_isolation.
The solution I got was changing the driver to Jasync.
//DB
implementation("com.github.jasync-sql:jasync-r2dbc-mysql:2.0.4")
implementation("io.r2dbc:r2dbc-h2")
implementation("org.springframework.boot:spring-boot-starter-data-r2dbc:2.6.0")
And my config:
#Configuration
#EnableTransactionManagement
#EnableConfigurationProperties(DbPropertiesConfig::class)
class DataSourceConfiguration {
#Configuration
class ProdMySQLConfiguration(#Autowired val dbPropertiesConfig: DbPropertiesConfig) : AbstractR2dbcConfiguration() {
#Bean
override fun connectionFactory(): ConnectionFactory =
JasyncConnectionFactory(MySQLConnectionFactory(
com.github.jasync.sql.db.Configuration(
database = dbPropertiesConfig.db,
port = dbPropertiesConfig.port,
username = dbPropertiesConfig.username,
host = dbPropertiesConfig.host,
password = dbPropertiesConfig.password
)
))
}
}
Taking into consideration I have that DbPropertiesConfig in my yml.
Doc/Example:
Doc
Example
Gitter: https://gitter.im/jasync-sql/support
I'm working on a new project which involves fuzzy search so was working on elasticsearch (v6.4.3) with spring boot (v2.1.5). I am unable to make connection between spring boot to elasticsearch since I have to pass username, password, ca_certificate_base64 from spring boot to elasticsearch to make connection. Could you please let me know how do I make connection and what elasticsearch client is correct option? A sample or link would be helpful.
Locally (my laptop), I did install elasticsearch 6 and spring boot 2.1.5. I was able to make connection (using spring data) since there was no 'https' connection required or pass username and password since most of the examples in internet talks about localhost:9200.
public Client client() {
Settings elasticsearchSettings = Settings.builder()
.put("client.transport.sniff", true)
.put("uri", "https://usertemp:ABCSAD#alp-usba-north-3-portal.11.db2lay.com:32117/")
.put("uri_direct_1", "https://usertemp:ABCSAD#alp-usba-north-3-portal.11.db2lay.com:32117/")
.put("cluster.name", clusterName).build();
TransportClient client = new PreBuiltTransportClient(elasticsearchSettings);
}
I also tried to update application.properties file
'''
spring.data.elasticsearch.cluster-name=ee842f-93042
spring.data.elasticsearch.cluster-nodes=alp-usba-north-3-portal.11.db2lay.com:32117
spring.data.elasticsearch.properties.username=usertemp
spring.data.elasticsearch.properties.password=ABCSAD
spring.data.elasticsearch.properties.ca_certificate_base64=SUZJQ0FURS0tLS0tCk1JSURvekNDQW91Z0F3SUJBZ0lFWFA5Sjl6QU5CZ2
I was expecting the connection with spring boot and elasticsearch. But, getting below error when I start the application server.
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.elasticsearch.client.transport.TransportClient]: Factory method 'elasticsearchClient' threw exception; nested exception is java.lang.IllegalArgumentException: unknown setting [password] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622) ~[spring-beans-5.1.7.RELEASE.jar:5.1.7.RELEASE]
... 96 common frames omitted
Caused by: java.lang.IllegalArgumentException: unknown setting [password] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
at org.elasticsearch.common.settings.AbstractScopedSettings.validate(AbstractScopedSettings.java:393) ~[elasticsearch-6.4.3.jar:6.4.3]
As I already mentioned in the comments, I don't know how exactly IBM Compose for Elasticsearch sets up the connection security; my setup for this scenario is as follows:
Elasticsearch
Elasticsearch 6.6.2 running on my machine
an NGINX running as proxy in front of Elasticsearch with
Basic Authentication activated
SSL only
SSL client certificates needed
maven and versions
In order to be able to communicate via HTTPS you need to use the RestClient which is available in Spring Data Elasticsearch as of version 3.2 (which currently is available in version 3.2.0.M4). Spring Boot 2.1.5 pulls in Spring Data Elasticsearch 3.1.8, so you need to override the version. You also need to specify the Elasticsearch version to match Spring Boot Data 3.2.0.M4, so your pom.xml needs the following entries:
<properties>
<java.version>1.8</java.version>
<elasticsearch.version>6.7.2</elasticsearch.version>
<spring-data-elasticsearch>3.2.0.M4</spring-data-elasticsearch>
</properties>
<repositories>
<repository>
<id>spring-libs-snapshot</id>
<name>Spring Snapshot Repository</name>
<url>https://repo.spring.io/libs-milestones</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
<version>${spring-data-elasticsearch}</version>
</dependency>
</dependencies>
Bean configuration
In your program you can configure the Beans for Spring Data Elasticsearch with an implementation of AbstractElasticsearchConfiguration:
#Configuration
public class RestClientConfig extends AbstractElasticsearchConfiguration {
private static final Logger LOG = LoggerFactory.getLogger(RestClientConfig.class);
private static final String CERT_FILE = "client.p12";
private static final String CERT_PASSWORD = "topsecret";
private static final String USER_NAME = "user";
private static final String USER_PASS = "password";
#Override
public RestHighLevelClient elasticsearchClient() {
final ClientConfiguration clientConfiguration = ClientConfiguration.builder()
.connectedTo("localhost:443") // set the address of the Elasticsearch cluster
.usingSsl(createSSLContext()) // use the SSLContext with the client cert
.withBasicAuth(USER_NAME, USER_PASS) // use the headers for authentication
.build();
return RestClients.create(clientConfiguration).rest();
}
private SSLContext createSSLContext() {
try {
SSLContext sslContext = SSLContext.getInstance("TLS");
KeyManager[] keyManagers = getKeyManagers();
sslContext.init(keyManagers, null, null);
return sslContext;
} catch (Exception e) {
LOG.error("cannot create SSLContext", e);
}
return null;
}
private KeyManager[] getKeyManagers()
throws KeyStoreException, NoSuchAlgorithmException, IOException, CertificateException, UnrecoverableKeyException {
try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(CERT_FILE)) {
KeyStore clientKeyStore = KeyStore.getInstance("PKCS12");
clientKeyStore.load(inputStream, CERT_PASSWORD.toCharArray());
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
kmf.init(clientKeyStore, CERT_PASSWORD.toCharArray());
return kmf.getKeyManagers();
}
}
#Bean
#Primary
public ElasticsearchOperations elasticsearchTemplate() {
return elasticsearchOperations();
}
}
With this setup I can run my Spring Boot application against the Elasticsearch cluster using ElasticsearchRestTemplate and ElasticsearchRepository.
You probably need to adjust the code in the getKeyManagers() method to match what you have from Compose, but this should give you some point from where to start.
I am trying to connect to an ActiveMQ broker running on my local machine using Spring Boot as followed from the this link
In the link, an in-memory broker is used but I am more keen on using a broker server, which in my case I am using ActiveMQ
I am specifying the activemq broker to Spring through the following configurations in the file application.properties present in the class path
spring.activemq.broker-url=stomp://localhost:61611
spring.activemq.password=password
spring.activemq.user=admin
Below are the dependencies from my pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-broker</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.activemq/activemq-stomp -->
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-stomp</artifactId>
</dependency>
</dependencies>
Below is the log for ActiveMQ after I have started the server on my local machine
INFO | Refreshing org.apache.activemq.xbean.XBeanBrokerFactory$1#5419f379: startup date [Sun May 07 07:17:36 IST 2017]; root of context hierarchy
INFO | Using Persistence Adapter: KahaDBPersistenceAdapter[F:\Softwares\Browser\apache-activemq-5.14.5-bin\apache-activemq-5.14.5\bin\..\data\kahadb]
INFO | KahaDB is version 6
INFO | Recovering from the journal #1:2260893
INFO | Recovery replayed 3154 operations from the journal in 0.309 seconds.
INFO | PListStore:[F:\Softwares\Browser\apache-activemq-5.14.5-bin\apache-activemq-5.14.5\bin\..\data\localhost\tmp_storage] started
INFO | Apache ActiveMQ 5.14.5 (localhost, ID:FOOTBALL_FIELD-63581-1494121658754-0:1) is starting
INFO | Listening for connections at: tcp://0.0.0.0:61610?maximumConnections=1000&wireFormat.maxFrameSize=104857600
INFO | Connector openwire started
INFO | Listening for connections at: amqp://0.0.0.0:5670?maximumConnections=1000&wireFormat.maxFrameSize=104857600
INFO | Connector amqp started
INFO | Listening for connections at: stomp://0.0.0.0:61611?maximumConnections=1000&wireFormat.maxFrameSize=104857600
INFO | Connector stomp started
INFO | Listening for connections at: mqtt://0.0.0.0:1880?maximumConnections=1000&wireFormat.maxFrameSize=104857600
INFO | Connector mqtt started
WARN | ServletContext#o.e.j.s.ServletContextHandler#338c99c8{/,null,STARTING} has uncovered http methods for path: /
INFO | Listening for connections at ws://127.0.0.1:61612?maximumConnections=1000&wireFormat.maxFrameSize=104857600
INFO | Connector ws started
INFO | Apache ActiveMQ 5.14.5 (localhost, ID:FOOTBALL_FIELD-63581-1494121658754-0:1) started
Application.java
#SpringBootApplication
#EnableJms
public class Application {
#Bean
public JmsListenerContainerFactory<?> myFactory(ConnectionFactory connectionFactory,
DefaultJmsListenerContainerFactoryConfigurer configurer) {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
// This provides all boot's default to this factory, including the message converter
configurer.configure(factory, connectionFactory);
// You could still override some of Boot's default if necessary.
return factory;
}
#Bean // Serialize message content to json using TextMessage
public MessageConverter jacksonJmsMessageConverter() {
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
converter.setTargetType(MessageType.TEXT);
converter.setTypeIdPropertyName("_type");
return converter;
}
public static void main(String[] args) {
// Launch the application
ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);
JmsTemplate jmsTemplate = context.getBean(JmsTemplate.class);
// Send a message with a POJO - the template reuse the message converter
System.out.println("Sending an email message.");
jmsTemplate.convertAndSend("mailbox", new Email("info#example.com", "Hello"));
}
}
Requesting DTO Class Email
public class Email {
private String to;
private String body;
//getter setters for fields
//constructors
#Override
public String toString() {
return String.format("Email{to=%s, body=%s}", getTo(), getBody());
}
}
Reponse DTO Class ** **
#Component
public class Receiver {
#JmsListener(destination = "mailbox", containerFactory = "myFactory")
public void receiveMessage(Email email) {
System.out.println("Received <" + email + ">");
}
}
Now when I execute the Spring Boot application, I am getting an error , the stacktrace of which is below
Exception in thread "main" org.springframework.jms.UncategorizedJmsException: Uncategorized exception occurred during JMS processing; nested exception is javax.jms.JMSException: Could not create Transport. Reason: java.lang.IllegalArgumentException: Invalid connect parameters: {wireFormat.host=localhost}
at org.springframework.jms.support.JmsUtils.convertJmsAccessException(JmsUtils.java:316)
at org.springframework.jms.support.JmsAccessor.convertJmsAccessException(JmsAccessor.java:169)
at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:487)
at org.springframework.jms.core.JmsTemplate.send(JmsTemplate.java:570)
at org.springframework.jms.core.JmsTemplate.convertAndSend(JmsTemplate.java:658)
at hello.Application.main(Application.java:49)
Caused by: javax.jms.JMSException: Could not create Transport. Reason: java.lang.IllegalArgumentException: Invalid connect parameters: {wireFormat.host=localhost}
at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:36)
at org.apache.activemq.ActiveMQConnectionFactory.createTransport(ActiveMQConnectionFactory.java:333)
at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:346)
at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:304)
at org.apache.activemq.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:244)
at org.springframework.jms.support.JmsAccessor.createConnection(JmsAccessor.java:180)
at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:474)
... 3 more
Caused by: java.lang.IllegalArgumentException: Invalid connect parameters: {wireFormat.host=localhost}
at org.apache.activemq.transport.TransportFactory.doConnect(TransportFactory.java:126)
at org.apache.activemq.transport.TransportFactory.connect(TransportFactory.java:65)
at org.apache.activemq.ActiveMQConnectionFactory.createTransport(ActiveMQConnectionFactory.java:331)
As a result of this, I am unable to connect to the ActiveMQ broker running on my local machine through Spring Boot.
My requirement is to build a JMS Sender and Receiver over STOMP through ActiveMQ broker in Spring Boot Only. But I am unable to connect to the STOMP URL of the instance f ActiveMQ running on my local.
UPDATE : 11.05.2017 :
After a lot of debugging, I managed to find out that at line # 120 of org.apache.activemq.transport.TransportFactory class has this code Transport transport = createTransport(location, wf) is calling the org.apache.activemq.transport.tcp.TcpTransportFactory implementation of org.apache.activemq.transport.TransportFactory instead of org.apache.activemq.transport.stomp.StompTransportFactory or as a matter of fact any of StompTransportFactory implementations available in activemq-stomp.jar being present in classpath. I want to know if any body can tell me how is the appropriate TransportFactory implementation is selected.
I am stuck on this for almost 3 days. Any type of help or suggestion would be appreciated :)
Cheers!
Is there any reason that you want to use STOMP in Java in place of using the normal ActiveMQ Java client and protocols like VM or TCP ?
STOMP is designed for plain text... your exception is due to the fact that you are using the ActiveMQ client to speak STOMP which it cannot do and to do this you need some other libraries for that maybe spring stomp support but it is not exactly what you try to do http://docs.spring.io/spring-integration/reference/html/stomp.html
if you need STOMP you can use this lib and configure the correspondant beans https://github.com/fusesource/stompjms
UPDATE
As i see in this test https://github.com/fusesource/stompjms/blob/master/stompjms-activemq-test/src/test/java/org/fusesource/stomp/activemq/ActiveMQJmsStompTest.java
It is easy to integrate this library to any java or spring client since it implements JMS API.
You have to define a bean for the ConnectionFactory :
add to your application.properties
jms.broker.url=tcp://localhost:61611
And update your configuration :
#Value("${jms.broker.url}")
public String host;
#Bean
public ConnectionFactory connectionFactory() throws Exception {
StompJmsConnectionFactory result = new StompJmsConnectionFactory();
result.setBrokerURI(host);
return result;
}
I am trying run a spring-boot application which uses hibernate via spring-jpa, but i am getting this error:
Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:104)
at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:71)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:205)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1885)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:398)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842)
at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:152)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:336)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1613)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1550)
... 21 more
my pom.xml file is this:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.8.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
</dependency>
</dependencies>
my hibernate configuration is that (the dialect configuration is in the last method from this class):
#Configuration
#EnableTransactionManagement
#ComponentScan({ "com.spring.app" })
public class HibernateConfig {
#Bean
public LocalSessionFactoryBean sessionFactory() {
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
sessionFactory.setDataSource(restDataSource());
sessionFactory.setPackagesToScan(new String[] { "com.spring.app.model" });
sessionFactory.setHibernateProperties(hibernateProperties());
return sessionFactory;
}
#Bean
public DataSource restDataSource() {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName("org.postgresql.Driver");
dataSource.setUrl("jdbc:postgresql://localhost:5432/teste?charSet=LATIN1");
dataSource.setUsername("klebermo");
dataSource.setPassword("123");
return dataSource;
}
#Bean
#Autowired
public HibernateTransactionManager transactionManager(SessionFactory sessionFactory) {
HibernateTransactionManager txManager = new HibernateTransactionManager();
txManager.setSessionFactory(sessionFactory);
return txManager;
}
#Bean
public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
return new PersistenceExceptionTranslationPostProcessor();
}
Properties hibernateProperties() {
return new Properties() {
/**
*
*/
private static final long serialVersionUID = 1L;
{
setProperty("hibernate.hbm2ddl.auto", "create");
setProperty("hibernate.show_sql", "false");
setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
}
};
}
}
what I am doing wrong here?
First remove all of your configuration Spring Boot will start it for you.
Make sure you have an application.properties in your classpath and add the following properties.
spring.datasource.url=jdbc:postgresql://localhost:5432/teste?charSet=LATIN1
spring.datasource.username=klebermo
spring.datasource.password=123
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=create
If you really need access to a SessionFactory and that is basically for the same datasource, then you can do the following (which is also documented here although for XML, not JavaConfig).
#Configuration
public class HibernateConfig {
#Bean
public HibernateJpaSessionFactoryBean sessionFactory(EntityManagerFactory emf) {
HibernateJpaSessionFactoryBean factory = new HibernateJpaSessionFactoryBean();
factory.setEntityManagerFactory(emf);
return factory;
}
}
That way you have both an EntityManagerFactory and a SessionFactory.
UPDATE: As of Hibernate 5 the SessionFactory actually extends the EntityManagerFactory. So to obtain a SessionFactory you can simply cast the EntityManagerFactory to it or use the unwrap method to get one.
public class SomeHibernateRepository {
#PersistenceUnit
private EntityManagerFactory emf;
protected SessionFactory getSessionFactory() {
return emf.unwrap(SessionFactory.class);
}
}
Assuming you have a class with a main method with #EnableAutoConfiguration you don't need the #EnableTransactionManagement annotation, as that will be enabled by Spring Boot for you. A basic application class in the com.spring.app package should be enough.
#Configuration
#EnableAutoConfiguration
#ComponentScan
public class Application {
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
Something like that should be enough to have all your classes (including entities and Spring Data based repositories) detected.
UPDATE: These annotations can be replaced with a single #SpringBootApplication in more recent versions of Spring Boot.
#SpringBootApplication
public class Application {
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
I would also suggest removing the commons-dbcp dependency as that would allow Spring Boot to configure the faster and more robust HikariCP implementation.
I was facing a similar problem when starting up the application (using Spring Boot) with the database server down.
Hibernate can determine the correct dialect to use automatically, but in order to do this, it needs a live connection to the database.
add spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQLDialect in application.properties file
I got this error when my database was not created. After creating the DB manually, it worked fine.
I also faced a similar issue. But, it was due to the invalid password provided. Also, I would like to say your code seems to be old-style code using spring. You already mentioned that you are using spring boot, which means most of the things will be auto configured for you. hibernate dialect will be auto selected based on the DB driver available on the classpath along with valid credentials which can be used to test the connection properly. If there is any issue with the connection you will again face the same error. only 3 properties needed in application.properties
# Replace with your connection string
spring.datasource.url=jdbc:mysql://localhost:3306/pdb1
# Replace with your credentials
spring.datasource.username=root
spring.datasource.password=
Remove the redundant Hibernate Configuration
If you're using Spring Boot, you don't need to provide the JPA and Hibernate configuration explicitly, as Spring Boot can do that for you.
Add database configuration properties
In the application.properties Spring Boot configuration file, you have the add your database configuration properties:
spring.datasource.driverClassName = org.postgresql.Driver
spring.datasource.url = jdbc:postgresql://localhost:5432/teste
spring.datasource.username = klebermo
spring.datasource.password = 123
Add Hibernate specific properties
And, in the same application.properties configuration file, you can also set custom Hibernate properties:
# Log SQL statements
spring.jpa.show-sql = false
# Hibernate ddl auto for generating the database schema
spring.jpa.hibernate.ddl-auto = create
# Hibernate database Dialect
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
That's it!
I ran into the same problem and my issue was that the DB I was trying to connect to didn't exist.
I created the DB, verified the URL/connection string and reran and everything worked as expected.
I had same issue. adding this to the application.properties solved the issue:
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
The following are some of the reasons for the hibernate.dialect not set issue.
Most of these exceptions are shown in the startup log which is finally followed by the mentioned issue.
Example: In Spring boot app with Postgres DB
1. Check if the database is actually installed and its server is started.
org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
java.net.ConnectException: Connection refused: connect
org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
2. Check if the database name is correctly mentioned.
org.postgresql.util.PSQLException: FATAL: database "foo" does not exist
In application.properties file,
spring.datasource.url = jdbc:postgresql://localhost:5432/foo
but foo didn't exist.
So I created the database from pgAdmin for postgres
CREATE DATABASE foo;
3. Check if the host name and server port is accessible.
org.postgresql.util.PSQLException: Connection to localhost:5431 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
java.net.ConnectException: Connection refused: connect
4. Check if the database credentials are correct.
as #Pankaj mentioned
org.postgresql.util.PSQLException: FATAL: password authentication failed for user "postgres"
spring.datasource.username= {DB USERNAME HERE}
spring.datasource.password= {DB PASSWORD HERE}
In spring boot for jpa java config you need to extend JpaBaseConfiguration and implement it's abstract methods.
#Configuration
public class JpaConfig extends JpaBaseConfiguration {
#Override
protected AbstractJpaVendorAdapter createJpaVendorAdapter() {
final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
return vendorAdapter;
}
#Override
protected Map<String, Object> getVendorProperties() {
Map<String, Object> properties = new HashMap<>();
properties.put("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
}
}
this is happening because your code is not bale to connect the database. Make sure you have mysql driver and username, password correct.
Make sure your application.properties has all correct info: (I changed my db port from 8889 to 3306 it worked)
db.url: jdbc:mysql://localhost:3306/test
It turns out there is no one mentioning set spring.jpa.database=mysql in application.properties file, if you use Spring JPA. This is the simplest answer to me and I want to share in this question.
In my case the user could not connect to the database. If will have same issue if the log contains a warning just before the exception:
WARN HHH000342: Could not obtain connection to query metadata : Login failed for user 'my_user'.
Make sure you have your database in your pom like OP did. That was my problem.
My problem was that embedded database was already connected. close connection
I got this issue when Eclipse was unable to find the JDBC driver. Had to do a gradle refresh from the eclipse to get this work.
I had the same issue and after debugging it turns out that Spring application.properties had wrong IP address for DB server
spring.datasource.url=jdbc:oracle:thin:#WRONG:1521/DEV
If you are using this line:
sessionFactory.getHibernateProperties().put("hibernate.dialect", env.getProperty("hibernate.dialect"));
make sure that env.getProperty("hibernate.dialect") is not null.
Same but in a JBoss WildFly AS.
Solved with properties in my META-INF/persistence.xml
<properties>
<property name="hibernate.transaction.jta.platform"
value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform" />
<property name="spring.jpa.database-platform" value="org.hibernate.dialect.PostgreSQLDialect" />
<property name="spring.jpa.show-sql" value="false" />
</properties>
For those working with AWS MySQL RDS, it may occur when you are unable to connect to the database. Go to AWS Security Groups setting for MySQL RDS and edit the inbound IP rule by refreshing MyIP.
I faced this issue and doing above got the problem fixed for me.
I also had this problem. In my case it was because of no grants were assigned to MySQL user. Assigning grants to MySQL user which my app uses resolved the issue:
grant select, insert, delete, update on my_db.* to 'my_user'#'%';
Adding spring.jpa.database-platform=org.hibernate.dialect.MariaDB53Dialect to my properties file worked for me.
PS: i'm using MariaDB
I reproduced this error message in the following three cases:
There does not exist database user with username written in application.properties file or persistence.properties file or, as in your case, in HibernateConfig file
The deployed database has that user but user is identified by different password than that in one of above files
The database has that user and the passwords match but that user does not have all privileges needed to accomplish all database tasks that your spring-boot app does
The obvious solution is to create new database user with the same username and password as in the spring-boot app or change username and password in your spring-boot app files to match an existing database user and grant sufficient privileges to that database user. In case of MySQL database this can be done as shown below:
mysql -u root -p
>CREATE USER 'theuser'#'localhost' IDENTIFIED BY 'thepassword';
>GRANT ALL ON *.* to theuser#localhost IDENTIFIED BY 'thepassword';
>FLUSH PRIVILEGES;
Obviously there are similar commands in Postgresql but I haven't tested if in case of Postgresql this error message can be reproduced in these three cases.
I had the same issue and it was caused by being unable to connect to the database instance. Look for hibernate error HHH000342 in the log above that error, it should give you an idea to where the db connection is failing (incorrect username/pass, url, etc.)
This happened to me because I hadn't added the conf.configure(); before beginning the session:
Configuration conf = new Configuration();
conf.configure();
Make sure that you have enter valid detail in application.properties and whether your database server is available. As a example when you are connecting with MySQL check whether XAMPP is running properly.
I faced the same issue: The db I was trying to connect did not exist. I used jpa.database=default (which I guess means it will try to connect to the database and then auto select the dialect). Once I started the database, it worked fine without any change.
I faced this issue due to Mysql 8.0.11 version reverting back to 5.7 solved for me
I had the same error after using the hibernate code generation
https://www.mkyong.com/hibernate/how-to-generate-code-with-hibernate-tools/
then the hibernate.cfg.xml was created in /src/main/java
but without the connection parameters
after removing it - my problem was solved
I am trying run a spring-boot application which uses hibernate via spring-jpa, but i am getting this error:
Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:104)
at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:71)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:205)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1885)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:398)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842)
at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:152)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:336)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1613)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1550)
... 21 more
my pom.xml file is this:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.8.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
</dependency>
</dependencies>
my hibernate configuration is that (the dialect configuration is in the last method from this class):
#Configuration
#EnableTransactionManagement
#ComponentScan({ "com.spring.app" })
public class HibernateConfig {
#Bean
public LocalSessionFactoryBean sessionFactory() {
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
sessionFactory.setDataSource(restDataSource());
sessionFactory.setPackagesToScan(new String[] { "com.spring.app.model" });
sessionFactory.setHibernateProperties(hibernateProperties());
return sessionFactory;
}
#Bean
public DataSource restDataSource() {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName("org.postgresql.Driver");
dataSource.setUrl("jdbc:postgresql://localhost:5432/teste?charSet=LATIN1");
dataSource.setUsername("klebermo");
dataSource.setPassword("123");
return dataSource;
}
#Bean
#Autowired
public HibernateTransactionManager transactionManager(SessionFactory sessionFactory) {
HibernateTransactionManager txManager = new HibernateTransactionManager();
txManager.setSessionFactory(sessionFactory);
return txManager;
}
#Bean
public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
return new PersistenceExceptionTranslationPostProcessor();
}
Properties hibernateProperties() {
return new Properties() {
/**
*
*/
private static final long serialVersionUID = 1L;
{
setProperty("hibernate.hbm2ddl.auto", "create");
setProperty("hibernate.show_sql", "false");
setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
}
};
}
}
what I am doing wrong here?
First remove all of your configuration Spring Boot will start it for you.
Make sure you have an application.properties in your classpath and add the following properties.
spring.datasource.url=jdbc:postgresql://localhost:5432/teste?charSet=LATIN1
spring.datasource.username=klebermo
spring.datasource.password=123
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=create
If you really need access to a SessionFactory and that is basically for the same datasource, then you can do the following (which is also documented here although for XML, not JavaConfig).
#Configuration
public class HibernateConfig {
#Bean
public HibernateJpaSessionFactoryBean sessionFactory(EntityManagerFactory emf) {
HibernateJpaSessionFactoryBean factory = new HibernateJpaSessionFactoryBean();
factory.setEntityManagerFactory(emf);
return factory;
}
}
That way you have both an EntityManagerFactory and a SessionFactory.
UPDATE: As of Hibernate 5 the SessionFactory actually extends the EntityManagerFactory. So to obtain a SessionFactory you can simply cast the EntityManagerFactory to it or use the unwrap method to get one.
public class SomeHibernateRepository {
#PersistenceUnit
private EntityManagerFactory emf;
protected SessionFactory getSessionFactory() {
return emf.unwrap(SessionFactory.class);
}
}
Assuming you have a class with a main method with #EnableAutoConfiguration you don't need the #EnableTransactionManagement annotation, as that will be enabled by Spring Boot for you. A basic application class in the com.spring.app package should be enough.
#Configuration
#EnableAutoConfiguration
#ComponentScan
public class Application {
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
Something like that should be enough to have all your classes (including entities and Spring Data based repositories) detected.
UPDATE: These annotations can be replaced with a single #SpringBootApplication in more recent versions of Spring Boot.
#SpringBootApplication
public class Application {
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
I would also suggest removing the commons-dbcp dependency as that would allow Spring Boot to configure the faster and more robust HikariCP implementation.
I was facing a similar problem when starting up the application (using Spring Boot) with the database server down.
Hibernate can determine the correct dialect to use automatically, but in order to do this, it needs a live connection to the database.
add spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQLDialect in application.properties file
I got this error when my database was not created. After creating the DB manually, it worked fine.
I also faced a similar issue. But, it was due to the invalid password provided. Also, I would like to say your code seems to be old-style code using spring. You already mentioned that you are using spring boot, which means most of the things will be auto configured for you. hibernate dialect will be auto selected based on the DB driver available on the classpath along with valid credentials which can be used to test the connection properly. If there is any issue with the connection you will again face the same error. only 3 properties needed in application.properties
# Replace with your connection string
spring.datasource.url=jdbc:mysql://localhost:3306/pdb1
# Replace with your credentials
spring.datasource.username=root
spring.datasource.password=
Remove the redundant Hibernate Configuration
If you're using Spring Boot, you don't need to provide the JPA and Hibernate configuration explicitly, as Spring Boot can do that for you.
Add database configuration properties
In the application.properties Spring Boot configuration file, you have the add your database configuration properties:
spring.datasource.driverClassName = org.postgresql.Driver
spring.datasource.url = jdbc:postgresql://localhost:5432/teste
spring.datasource.username = klebermo
spring.datasource.password = 123
Add Hibernate specific properties
And, in the same application.properties configuration file, you can also set custom Hibernate properties:
# Log SQL statements
spring.jpa.show-sql = false
# Hibernate ddl auto for generating the database schema
spring.jpa.hibernate.ddl-auto = create
# Hibernate database Dialect
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
That's it!
I ran into the same problem and my issue was that the DB I was trying to connect to didn't exist.
I created the DB, verified the URL/connection string and reran and everything worked as expected.
I had same issue. adding this to the application.properties solved the issue:
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
The following are some of the reasons for the hibernate.dialect not set issue.
Most of these exceptions are shown in the startup log which is finally followed by the mentioned issue.
Example: In Spring boot app with Postgres DB
1. Check if the database is actually installed and its server is started.
org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
java.net.ConnectException: Connection refused: connect
org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
2. Check if the database name is correctly mentioned.
org.postgresql.util.PSQLException: FATAL: database "foo" does not exist
In application.properties file,
spring.datasource.url = jdbc:postgresql://localhost:5432/foo
but foo didn't exist.
So I created the database from pgAdmin for postgres
CREATE DATABASE foo;
3. Check if the host name and server port is accessible.
org.postgresql.util.PSQLException: Connection to localhost:5431 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
java.net.ConnectException: Connection refused: connect
4. Check if the database credentials are correct.
as #Pankaj mentioned
org.postgresql.util.PSQLException: FATAL: password authentication failed for user "postgres"
spring.datasource.username= {DB USERNAME HERE}
spring.datasource.password= {DB PASSWORD HERE}
In spring boot for jpa java config you need to extend JpaBaseConfiguration and implement it's abstract methods.
#Configuration
public class JpaConfig extends JpaBaseConfiguration {
#Override
protected AbstractJpaVendorAdapter createJpaVendorAdapter() {
final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
return vendorAdapter;
}
#Override
protected Map<String, Object> getVendorProperties() {
Map<String, Object> properties = new HashMap<>();
properties.put("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
}
}
this is happening because your code is not bale to connect the database. Make sure you have mysql driver and username, password correct.
Make sure your application.properties has all correct info: (I changed my db port from 8889 to 3306 it worked)
db.url: jdbc:mysql://localhost:3306/test
It turns out there is no one mentioning set spring.jpa.database=mysql in application.properties file, if you use Spring JPA. This is the simplest answer to me and I want to share in this question.
In my case the user could not connect to the database. If will have same issue if the log contains a warning just before the exception:
WARN HHH000342: Could not obtain connection to query metadata : Login failed for user 'my_user'.
Make sure you have your database in your pom like OP did. That was my problem.
My problem was that embedded database was already connected. close connection
I got this issue when Eclipse was unable to find the JDBC driver. Had to do a gradle refresh from the eclipse to get this work.
I had the same issue and after debugging it turns out that Spring application.properties had wrong IP address for DB server
spring.datasource.url=jdbc:oracle:thin:#WRONG:1521/DEV
If you are using this line:
sessionFactory.getHibernateProperties().put("hibernate.dialect", env.getProperty("hibernate.dialect"));
make sure that env.getProperty("hibernate.dialect") is not null.
Same but in a JBoss WildFly AS.
Solved with properties in my META-INF/persistence.xml
<properties>
<property name="hibernate.transaction.jta.platform"
value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform" />
<property name="spring.jpa.database-platform" value="org.hibernate.dialect.PostgreSQLDialect" />
<property name="spring.jpa.show-sql" value="false" />
</properties>
For those working with AWS MySQL RDS, it may occur when you are unable to connect to the database. Go to AWS Security Groups setting for MySQL RDS and edit the inbound IP rule by refreshing MyIP.
I faced this issue and doing above got the problem fixed for me.
I also had this problem. In my case it was because of no grants were assigned to MySQL user. Assigning grants to MySQL user which my app uses resolved the issue:
grant select, insert, delete, update on my_db.* to 'my_user'#'%';
Adding spring.jpa.database-platform=org.hibernate.dialect.MariaDB53Dialect to my properties file worked for me.
PS: i'm using MariaDB
I reproduced this error message in the following three cases:
There does not exist database user with username written in application.properties file or persistence.properties file or, as in your case, in HibernateConfig file
The deployed database has that user but user is identified by different password than that in one of above files
The database has that user and the passwords match but that user does not have all privileges needed to accomplish all database tasks that your spring-boot app does
The obvious solution is to create new database user with the same username and password as in the spring-boot app or change username and password in your spring-boot app files to match an existing database user and grant sufficient privileges to that database user. In case of MySQL database this can be done as shown below:
mysql -u root -p
>CREATE USER 'theuser'#'localhost' IDENTIFIED BY 'thepassword';
>GRANT ALL ON *.* to theuser#localhost IDENTIFIED BY 'thepassword';
>FLUSH PRIVILEGES;
Obviously there are similar commands in Postgresql but I haven't tested if in case of Postgresql this error message can be reproduced in these three cases.
I had the same issue and it was caused by being unable to connect to the database instance. Look for hibernate error HHH000342 in the log above that error, it should give you an idea to where the db connection is failing (incorrect username/pass, url, etc.)
This happened to me because I hadn't added the conf.configure(); before beginning the session:
Configuration conf = new Configuration();
conf.configure();
Make sure that you have enter valid detail in application.properties and whether your database server is available. As a example when you are connecting with MySQL check whether XAMPP is running properly.
I faced the same issue: The db I was trying to connect did not exist. I used jpa.database=default (which I guess means it will try to connect to the database and then auto select the dialect). Once I started the database, it worked fine without any change.
I faced this issue due to Mysql 8.0.11 version reverting back to 5.7 solved for me
I had the same error after using the hibernate code generation
https://www.mkyong.com/hibernate/how-to-generate-code-with-hibernate-tools/
then the hibernate.cfg.xml was created in /src/main/java
but without the connection parameters
after removing it - my problem was solved