Reputation: 309
I have searched on StackOverflow for similar problems, and if I remove
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
everything works. However I need the data-jpa.
I have created 2 POJOs:
@Entity
public class Author {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String firstName;
private String lastName;
@ManyToMany
private Set<Book> books = new HashSet<>();
public Author(){}
}
And the second one:
@Entity
public class Book {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String title;
private String isbn;
private String publisher;
@ManyToMany
private Set<Author> authors = new HashSet<>();
public Book(String title, String isbn, String publisher) {
this.title = title;
this.isbn = isbn;
this.publisher = publisher;
}
}
I have added 2 Entities and as I understand, I should no longer get the error At least one JPA metamodel must be present
. Why I get this error?
DemoApplication.class
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
My pom.xml dependencies:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.4.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.2.3.Final</version>
</dependency>
</dependencies>
Upvotes: 0
Views: 550
Reputation: 2444
I am to low in reputation so i can't comment the question.
Can you share your full maven pom.xml
please? The solution you are referencing is this answer i guess? In this answer they do not recommend to remove spring-boot-starter-data-jpa
but to remove an explicit dependency to an "old" spring-data-jpa
.
Make sure to share your pom file, i can only guess right now.
Update:
The dependencies hibernate-core
and hibernate-entititymanager
are already provided by spring-boot-starter-jpa
and you override the managed versions with your custom versions which leads to your error.
Try to remove your explicit hibernate-*
dependencies.
Upvotes: 4