spring-guides / gs-accessing-data-mysql

Accessing data with MySQL :: Learn how to set up and manage user accounts on MySQL and how to configure Spring Boot to connect to it at runtime.

Home Page:http://spring.io/guides/gs/accessing-data-mysql/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"Accessing data with MySQL" guide does not work

james-bates-omio opened this issue · comments

Following the steps in https://spring.io/guides/gs/accessing-data-mysql/ to the letter, the application fails to start with the following 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:100) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
	at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:54) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
	at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:137) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
	at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
	at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:94) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
	at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
	... 33 common frames omitted

Presumably, some configuration is missing. Or Spring boot is broken.

How about if you just take the "complete" sample from the source code? It works for me. Kind of looks like maybe you don't have MySQL running, or it hasn't been configured right?

try add 'spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect' to application.properties

You don’t need to do that, though, if the application can connect to the database (it will figure out the dialect).

I used the "complete" from this guide in Android Studio. But when i close the project and run it again, I face the following error:

APPLICATION FAILED TO START

Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

What is wrong with this project?

So maybe the database isn’t running?

Mysql db is running. Also when I firstly open the project in Android Studio, the connection is fine. The error appears when I close the project and run it again. I think something is going wrong after some synchronizing by Android Studio, or something about Maven and Gradle.

I don't know how Android Studio could be making a difference. How about if you run the app from the command line (e.g. ./mvnw spring-boot:run)? Does it work there? The error is telling us you can't connect to the database. Is it running on localhost? Did you change anything about the database when you restarted the app? Some more logs might shed some light.

I think the error is telling us "url" is not able to be configured. But no changes before restarting the app. Its happening every time I am deleting the project, then downloading again from spring.io and running, and restarting Android Studio and running again. Maybe something about Maven and Gradle at the same time in this project?

Let's leave Android Studio out of it for now. Can you run the project (with either Maven or Gradle) from the command line? If not please attach logs.

Thank you for the response.
Yes, it's up right now. I did it with Maven.
What do you think is the matter with AS?

What do you think is the matter with AS?

No idea. Ask in an Android forum?

commented

This works for me 👌