Romain Angier
Romain Angier

Reputation: 3

My Java Spring Boot Maven REST API doesn't work

I'm starting in Java J2E and I'm following this tutorial to develop a REST API with Java, Spring Boot and Maven.

I don't understand the following error, someone please explain to me?.... :/ My code: https://github.com/AngierRomain/API-REST-Spring-Java-Maven

The error is in the ERROR.txt file

Thank you in advance for your help!

Upvotes: 0

Views: 997

Answers (1)

javaGroup456
javaGroup456

Reputation: 333

I can see you have added the dependency in your pom :

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

You have also created a Repository class. I am assuming that you want to use Postgres Db to fetch/store the Blog details.

On running this spring application, getting this error

org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set

This is because you are trying to use data-Jpa( pom dependency) and also postgres (dependency is present in pom) but you haven't provided the dialect and connection details in your application.properties.

Add this in application.properties

spring.datasource.url=jdbc:postgresql://localhost:5432/blog
spring.datasource.username= root
spring.datasource.password= root
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect

Now, getting this error from entity manager :

java.lang.IllegalArgumentException: Not a managed type: class me.romain.Blog

In your repository class, your Entity class has been specified as Blog.java

public interface BlogRepository extends JpaRepository<Blog, Integer>

If you see your Blog class, it is a plain POJO class. It is not DTO. DTO is responsible for interacting with the database. To make a POJO an entity class you have to specify it.

You can do this using Entity and Id annotation of javax.persistence package

import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
public class Blog {

    @Id
    private int id;
}

Now, that you have followed all this and all the data source connection details are right, I think it should work for you.

Note: You should try saving some sample data in DB and fetch it from there to check if it really works.


If you want just your current code to work, Remove Repository class, remove the spring-boot-starter-data-jpa dependency from pom. And you should be able to run your application.

Upvotes: 2

Related Questions