I have some issue and what's special - project worked correctly around 14 days and ever today, 30 minutes ago, I lucky launch him one time...and after that again have an issue.
For begin I want to add is the proof that everything worked half an hour ago:
We can see - run time for executing all process: 107411ms(107sec)
So. I developed spring project, which works with database using JpaRepository interface implementing.
Have issue, when I try to sent a post method into Controller from console:
curl -d '{"explorerId":'24', "turnOff":true}' -H "Content-Type: application/json" -X POST http://localhost:8080/vdtw
Variant 1
- "variant 1" (with @ManyToOne(cascade = CascadType.ALL, fetch = FetchType.EAGER) annotations in entity (showed in Structure section))
program starts, and after few second returns error in console:
{"timestamp":"2018-09-18T10:01:08.343+0000","status":500,"error":"Internal Server Error","message":"No message available","path":"/vdtw"}
In IDEA console throws error: **StackOverflowException: null* with preview:
* java.lang.instrument ASSERTION FAILED *: "!errorOutstanding" with message transform method call failed at JPLISAgent.c line: 844
2018-09-18 13:01:08.306 ERROR 25853 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.StackOverflowError] with root cause
prinscrn:
Variant 2 (with fetch = FetchType.LAZY, no CascadType set)
In this case, program works normally, but so long time (10+ minutes):
Generate vacancy description to word, parse 14885 words. Time: 621304
Questions:
Why did the program work normally for 14 days and is now starting to throw StackOverflowException?
How to optimize the structure for faster storage of entities in the database?
Structure:
The object stored in the database:
@Entity(name = "vacancy_desc_to_words")
public class VacancyDescriptionToWords {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@JoinColumn(name = "vacancy_description_id")
@ManyToOne(cascade = CascadeType.ALL)
private VacancyDescription vacancyDescription;
@JoinColumn(name = "words_id")
@ManyToOne(cascade = CascadType.ALL);
//------------------Second variant---------------------------
//@ManyToOne
private Words words;
}
Linked by ManyToOne entity:
@Entity(name = "words")
public class Words {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(name = "word", unique = true)
private String word;
@JsonIgnore
@OneToMany(mappedBy = "words", fetch = FetchType.EAGER, CascadType.ALL)
//---------------------Second variant----------------------
//@OneToMany(mappedBy = "words", fetch = FetchType.LAZY)
private Set<VacancyDescriptionToWords> vacancyDescriptionToWordsSet;
//getters/setters
}
Pom.xml:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Place in the code where the problem occurs
List<VacancyDescriptionToWords> vdtwList = VDTWService.parseAndGenerateNewDescToWords(vacancyDescriptions);
//--------------- exception string ----------------------
VDTWService.saveAll(vdtwList);
Saving list of entities way:
public void saveAll(List<VacancyDescriptionToWords> vdtwList) {
vdtwRepository.saveAll(vdtwList);
}
Repository:
public interface VDTWRepository extends JpaRepository<VacancyDescriptionToWords, Long> {
}
List– Valentyn Hruzytskyi Sep 18 '18 at 10:51saveAll(Iterablevar1);