我在StackOverflow上搜索过类似的问题,如果我删除了
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
一切正常。但是我需要data-jpa。
我创建了2个POJO:
@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(){}
}
第二个:
@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;
}
}
我添加了2个实体,据我了解,我不应再收到错误At least one JPA metamodel must be present
。为什么我会收到此错误?
DemoApplication.class
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
我的 pom.xml 依赖项:
<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>
答案 0 :(得分:4)
我的声誉很低,所以我不能评论这个问题。
你可以分享你的完整专家pom.xml
吗?您推荐的解决方案是this answer我猜?在此回答中,他们不建议删除spring-boot-starter-data-jpa
,而是删除对“旧”spring-data-jpa
的明确依赖。
请务必分享您的pom文件,我现在只能猜测。
<强>更新强>
依赖关系hibernate-core
和hibernate-entititymanager
已由spring-boot-starter-jpa
提供,您可以使用自定义版本覆盖托管版本,从而导致错误。
尝试删除明确的hibernate-*
依赖项。