简体   繁体   中英

Spring Data JPA: Example from Spring in Action don't run

I try to start an example from Spring in action 5. STS shows me the error:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2019-06-24 10:47:06.472 ERROR 6300 --- [ restartedMain] osboot.SpringApplication
: Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister

This's example may receive there: GitHub - Spring in action: Spring Data JPA

Can you help me? If need yet codes from example, I can copy here.

This example does not run with Java > 8.

You have to use Java 8 to run it as it is.

Spring Boot 2.0.x does not support Java 11.

You should upgrade the example to 2.1.6

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.6.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>

I try to re-produce your error, I catch the same

Caused by: org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister

I read comment Spring Data JPA: Example from Spring in Action don't run

Changing

@NoArgsConstructor(access=AccessLevel.PRIVATE, force=true)

to

@NoArgsConstructor(access=AccessLevel.PUBLIC, force=true)

does not resolve problem. Keep it like original.

Solution:

(1) I am using JDK 12. Add dependency

<!-- https://mvnrepository.com/artifact/org.javassist/javassist -->
<dependency>
    <groupId>org.javassist</groupId>
    <artifactId>javassist</artifactId>
    <version>3.25.0-GA</version>
</dependency>

(2) Program argumnet

--illegal-access=ignore

Result: In console log, applicaton run sucesss

Hibernate: insert into ingredient (name, type, id) values (?, ?, ?)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM