1
votes

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] o.s.boot.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.

2
Sorry, I don't understand what I must do? My Inrdedient.java is the same as the GitHub. Should I add something? - Alexander Lopatin

2 Answers

0
votes

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 (?, ?, ?)

0
votes

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>