[英]Having a `java.lang.StackOverflowError: null` when running a findById(Long id) Jpa method on a specific Entity with bidirectional connection
I am having a problem with a findById Jpa method for a specific Entity ( CtThhlastikaPressThreats
). 我对特定实体( CtThhlastikaPressThreats
)的findById Jpa方法有问题。
To clarify more about the project it uses Spring Boot, Jpa and MySQL. 为了澄清有关该项目的更多信息,它使用Spring Boot,Jpa和MySQL。
There are Entities with bidirectional connections @OneToMany
and @ManyToOne
while also there is a mappedBy
between them and a JoinColumn
. 有双向连接实体@OneToMany
和@ManyToOne
同时还存在mappedBy
他们之间JoinColumn
。
The specific Entity for which I am encountering the problem has a similar bidirectional connection as the DeigmaThhlastikwn
Entity ( which has no problem, I once encountered a StackOverflow Exception but it was solved with an annotation of @JsonIgnore
. I tried it on this one as well as you can see on the @ManyToOne
side DeigmaThhlastikwnXPressThreats
Entity but it didn't work ) 我遇到问题的特定实体与DeigmaThhlastikwn
实体具有相似的双向连接(这没有问题,我曾经遇到StackOverflow异常,但使用@JsonIgnore
的注释解决了该问题。我也对此进行了尝试如您在@ManyToOne
端看到的DeigmaThhlastikwnXPressThreats
实体,但它不起作用)
CtThhlastikaPressThreatsController
Rest Controller : CtThhlastikaPressThreatsController
Rest控制器:
@RestController
@RequestMapping(CtThhlastikaPressThreatsController.BASE_URL)
public class CtThhlastikaPressThreatsController {
public static final String BASE_URL = "/v1/ctThhlastikaPressThreats";
private CtThhlastikaPressThreatsService ctThhlastikaPressThreatsService;
@Autowired
private CtThhlastikaPressThreatsRepositoryImpl ctThhlastikaPressThreatsRepository;
public CtThhlastikaPressThreatsController(CtThhlastikaPressThreatsService ctThhlastikaPressThreatsService) {
this.ctThhlastikaPressThreatsService = ctThhlastikaPressThreatsService;
}
@CrossOrigin
@GetMapping({"/{id}"})
public CtThhlastikaPressThreats findById(@PathVariable Long id){
return ctThhlastikaPressThreatsRepository.findCtThhlastikaPressThreatsById(id);
}
@CrossOrigin
@PostMapping()
public CtThhlastikaPressThreats addPressThreat(@RequestBody CtThhlastikaPressThreatDTO ctThhlastikaPressThreatDTO){
try {
return ctThhlastikaPressThreatsService.addPressThreat(ctThhlastikaPressThreatDTO);
}catch (Exception e){
throw e;
}
}
@CrossOrigin
@GetMapping({"/getAllActCodes"})
public ArrayList<String> getAllActCodes(){
try {
return ctThhlastikaPressThreatsService.getAllActCodes();
}catch (Exception e){
throw e;
}
}
}
CtThhlastikaPressThreats
Entity : CtThhlastikaPressThreats
实体:
package com.teicm.kerkinibackend.domain;
import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;
@Entity
public class CtThhlastikaPressThreats {
@Id
@Column(name = "id", nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "ctThhlastikaPressThreats")
private Set<DeigmaThhlastikwnXPressThreats> deigmaThhlastikwnXPressThreatsSet = new HashSet<>();
@Column(name = "act_code", unique = true, length = 50)
private String actCode;
@Column(name = "description_en")
private String descriptionEn;
@Column(name = "remarks")
private String remarks;
public CtThhlastikaPressThreats addPressThreat(DeigmaThhlastikwnXPressThreats deigmaThhlastikwnXPressThreats){
deigmaThhlastikwnXPressThreats.setCtThhlastikaPressThreats(this);
this.deigmaThhlastikwnXPressThreatsSet.add(deigmaThhlastikwnXPressThreats);
return this;
}
public CtThhlastikaPressThreats() {
}
public CtThhlastikaPressThreats(String actCode, Set<DeigmaThhlastikwnXPressThreats> deigmaThhlastikwnXPressThreatsSet, String descriptionEn, String remarks) {
this.actCode = actCode;
this.deigmaThhlastikwnXPressThreatsSet = deigmaThhlastikwnXPressThreatsSet;
this.descriptionEn = descriptionEn;
this.remarks = remarks;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getActCode() {
return actCode;
}
public void setActCode(String actCode) {
this.actCode = actCode;
}
public Set<DeigmaThhlastikwnXPressThreats> getDeigmaThhlastikwnXPressThreatsSet() {
return deigmaThhlastikwnXPressThreatsSet;
}
public void setDeigmaThhlastikwnXPressThreatsSet(Set<DeigmaThhlastikwnXPressThreats> deigmaThhlastikwnXPressThreatsSet) {
this.deigmaThhlastikwnXPressThreatsSet = deigmaThhlastikwnXPressThreatsSet;
}
public String getDescriptionEn() {
return descriptionEn;
}
public void setDescriptionEn(String descriptionEn) {
this.descriptionEn = descriptionEn;
}
public String getRemarks() {
return remarks;
}
public void setRemarks(String remarks) {
this.remarks = remarks;
}
}
DeigmaThhlastikwnXPressThreats
Entity : DeigmaThhlastikwnXPressThreats
实体:
package com.teicm.kerkinibackend.domain;
import com.fasterxml.jackson.annotation.JsonIgnore;
import javax.persistence.*;
@Entity
public class DeigmaThhlastikwnXPressThreats {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "deigma_thhlastikwn_id")
@JsonIgnore
private DeigmaThhlastikwn deigmaThhlastikwn;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "ct_thhlastika_press_threats_id")
@JsonIgnore
private CtThhlastikaPressThreats ctThhlastikaPressThreats;
@Column(name = "kwdikos_eidous", length = 50)
private String kwdikosEidous;
@Column(name = "press_threat", length = 50)
private String pressThreat;
@Column(name = "importance", length = 50)
private String importance;
public DeigmaThhlastikwnXPressThreats() {
}
public DeigmaThhlastikwnXPressThreats(DeigmaThhlastikwn deigmaThhlastikwn, CtThhlastikaPressThreats ctThhlastikaPressThreats, String kwdikosEidous, String pressThreat, String importance) {
this.deigmaThhlastikwn = deigmaThhlastikwn;
this.ctThhlastikaPressThreats = ctThhlastikaPressThreats;
this.kwdikosEidous = kwdikosEidous;
this.pressThreat = pressThreat;
this.importance = importance;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public DeigmaThhlastikwn getDeigmaThhlastikwn() {
return deigmaThhlastikwn;
}
public void setDeigmaThhlastikwn(DeigmaThhlastikwn deigmaThhlastikwn) {
this.deigmaThhlastikwn = deigmaThhlastikwn;
}
public CtThhlastikaPressThreats getCtThhlastikaPressThreats() {
return ctThhlastikaPressThreats;
}
public void setCtThhlastikaPressThreats(CtThhlastikaPressThreats ctThhlastikaPressThreats) {
this.ctThhlastikaPressThreats = ctThhlastikaPressThreats;
}
public String getKwdikosEidous() {
return kwdikosEidous;
}
public void setKwdikosEidous(String kwdikosEidous) {
this.kwdikosEidous = kwdikosEidous;
}
public String getPressThreat() {
return pressThreat;
}
public void setPressThreat(String pressThreat) {
this.pressThreat = pressThreat;
}
public String getImportance() {
return importance;
}
public void setImportance(String importance) {
this.importance = importance;
}
}
DeigmaThhlastikwn
Entity : DeigmaThhlastikwn
实体:
package com.teicm.kerkinibackend.domain;
import javax.persistence.*;
import java.sql.Date;
import java.sql.Time;
import java.util.HashSet;
import java.util.Set;
@Entity
@Table(name = "deigma_thhlastikwn")
public class DeigmaThhlastikwn {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
private Long id;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "deigmaThhlastikwn", fetch = FetchType.EAGER)
private Set<DeigmaThhlastikwnXEidh> deigmaThhlastikwnXEidhSet = new HashSet<>();
@OneToMany(cascade = CascadeType.ALL, mappedBy = "deigmaThhlastikwn", fetch = FetchType.EAGER)
private Set<DeigmaThhlastikwnXPressThreats> deigmaThhlastikwnXPressThreatsSet = new HashSet<>();
@Column(name = "kwdikos_deigmatos", nullable = false)
private String kwdikosDeigmatolhpsias;
@Column(name = "xrhmatodothsh")
private String xrhmatodothsh;
@Column(name = "ereunhths")
private String ereunhths;
@Column(name = "topothesia")
private String topothesia;
@Column(name = "date")
private Date date;
@Column(name = "time")
private Time time;
@Column(name = "diarkeia", length = 40)
private String diarkeia;
@Column(name = "tupos_vlasthshs")
private String tuposVlasthshs;
@Column(name = "tupos_oikotopou")
private String tupos_Oikotopou;
@Column(name = "epifaneia_deigmatolhpsias")
private Integer epifaneiaDeigmatolhpsias;
@Column(name = "latitude_egsa")
private Double latitudeEGSA;
@Column(name = "longitude_egsa")
private Double longitudeEGSA;
// Preferred for Google Maps Markers
@Column(name = "latitude_wgs84")
private Double latitudeWGS84;
// Preferred for Google Maps Markers
@Column(name = "longitude_wgs84")
private Double longitudeWGS84;
@Column(name = "grid_cell", length = 30)
private String gridCell;
@Column(name = "kwdikos_natura", length = 20)
private String kwdikosNatura;
@Column(name = "methodos_deigmatolhpsias")
private String methodosDeigmatolhpsias;
@Column(name = "parathrhseis")
private String parathrhseis;
@Column(name = "nomos")
private String nomos;
@Column(name = "picture")
@Lob
private Byte picture;
@Column(name = "file")
@Lob
private Byte file;
public DeigmaThhlastikwn() {
}
public DeigmaThhlastikwn(Set<DeigmaThhlastikwnXEidh> deigmaThhlastikwnXEidhSet, Set<DeigmaThhlastikwnXPressThreats> deigmaThhlastikwnXPressThreatsSet, String kwdikosDeigmatolhpsias, String xrhmatodothsh, String ereunhths, String topothesia, Date date, Time time, String diarkeia, String tuposVlasthshs, String tupos_Oikotopou, Integer epifaneiaDeigmatolhpsias, Double latitudeEGSA, Double longitudeEGSA, Double latitudeWGS84, Double longitudeWGS84, String gridCell, String kwdikosNatura, String methodosDeigmatolhpsias, String parathrhseis, String nomos, Byte picture, Byte file) {
this.deigmaThhlastikwnXEidhSet = deigmaThhlastikwnXEidhSet;
this.deigmaThhlastikwnXPressThreatsSet = deigmaThhlastikwnXPressThreatsSet;
this.kwdikosDeigmatolhpsias = kwdikosDeigmatolhpsias;
this.xrhmatodothsh = xrhmatodothsh;
this.ereunhths = ereunhths;
this.topothesia = topothesia;
this.date = date;
this.time = time;
this.diarkeia = diarkeia;
this.tuposVlasthshs = tuposVlasthshs;
this.tupos_Oikotopou = tupos_Oikotopou;
this.epifaneiaDeigmatolhpsias = epifaneiaDeigmatolhpsias;
this.latitudeEGSA = latitudeEGSA;
this.longitudeEGSA = longitudeEGSA;
this.latitudeWGS84 = latitudeWGS84;
this.longitudeWGS84 = longitudeWGS84;
this.gridCell = gridCell;
this.kwdikosNatura = kwdikosNatura;
this.methodosDeigmatolhpsias = methodosDeigmatolhpsias;
this.parathrhseis = parathrhseis;
this.nomos = nomos;
this.picture = picture;
this.file = file;
}
// Custom method for adding a new PressThreat for a specific DeigmaThhlastikwn allong with specifying the parent's id in the child object.
public DeigmaThhlastikwn addPressThreat(DeigmaThhlastikwnXPressThreats deigmaThhlastikwnXPressThreats){
deigmaThhlastikwnXPressThreats.setDeigmaThhlastikwn(this);
this.deigmaThhlastikwnXPressThreatsSet.add(deigmaThhlastikwnXPressThreats);
return this;
}
public DeigmaThhlastikwn addXEidh(DeigmaThhlastikwnXEidh deigmaThhlastikwnXEidh){
deigmaThhlastikwnXEidh.setDeigmaThhlastikwn(this);
this.deigmaThhlastikwnXEidhSet.add(deigmaThhlastikwnXEidh);
return this;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Set<DeigmaThhlastikwnXEidh> getDeigmaThhlastikwnXEidhSet() {
return deigmaThhlastikwnXEidhSet;
}
public void setDeigmaThhlastikwnXEidhSet(Set<DeigmaThhlastikwnXEidh> deigmaThhlastikwnXEidhSet) {
this.deigmaThhlastikwnXEidhSet = deigmaThhlastikwnXEidhSet;
}
public Set<DeigmaThhlastikwnXPressThreats> getDeigmaThhlastikwnXPressThreatsSet() {
return deigmaThhlastikwnXPressThreatsSet;
}
public void setDeigmaThhlastikwnXPressThreatsSet(Set<DeigmaThhlastikwnXPressThreats> deigmaThhlastikwnXPressThreatsSet) {
this.deigmaThhlastikwnXPressThreatsSet = deigmaThhlastikwnXPressThreatsSet;
}
public String getKwdikosDeigmatolhpsias() {
return kwdikosDeigmatolhpsias;
}
public void setKwdikosDeigmatolhpsias(String kwdikosDeigmatolhpsias) {
this.kwdikosDeigmatolhpsias = kwdikosDeigmatolhpsias;
}
public String getXrhmatodothsh() {
return xrhmatodothsh;
}
public void setXrhmatodothsh(String xrhmatodothsh) {
this.xrhmatodothsh = xrhmatodothsh;
}
public String getEreunhths() {
return ereunhths;
}
public void setEreunhths(String ereunhths) {
this.ereunhths = ereunhths;
}
public String getTopothesia() {
return topothesia;
}
public void setTopothesia(String topothesia) {
this.topothesia = topothesia;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public Time getTime() {
return time;
}
public void setTime(Time time) {
this.time = time;
}
public String getDiarkeia() {
return diarkeia;
}
public void setDiarkeia(String diarkeia) {
this.diarkeia = diarkeia;
}
public String getTuposVlasthshs() {
return tuposVlasthshs;
}
public void setTuposVlasthshs(String tuposVlasthshs) {
this.tuposVlasthshs = tuposVlasthshs;
}
public String getTupos_Oikotopou() {
return tupos_Oikotopou;
}
public void setTupos_Oikotopou(String tupos_Oikotopou) {
this.tupos_Oikotopou = tupos_Oikotopou;
}
public Integer getEpifaneiaDeigmatolhpsias() {
return epifaneiaDeigmatolhpsias;
}
public void setEpifaneiaDeigmatolhpsias(Integer epifaneiaDeigmatolhpsias) {
this.epifaneiaDeigmatolhpsias = epifaneiaDeigmatolhpsias;
}
public Double getLatitudeEGSA() {
return latitudeEGSA;
}
public void setLatitudeEGSA(Double latitudeEGSA) {
this.latitudeEGSA = latitudeEGSA;
}
public Double getLongitudeEGSA() {
return longitudeEGSA;
}
public void setLongitudeEGSA(Double longitudeEGSA) {
this.longitudeEGSA = longitudeEGSA;
}
public Double getLatitudeWGS84() {
return latitudeWGS84;
}
public void setLatitudeWGS84(Double latitudeWGS84) {
this.latitudeWGS84 = latitudeWGS84;
}
public Double getLongitudeWGS84() {
return longitudeWGS84;
}
public void setLongitudeWGS84(Double longitudeWGS84) {
this.longitudeWGS84 = longitudeWGS84;
}
public String getGridCell() {
return gridCell;
}
public void setGridCell(String gridCell) {
this.gridCell = gridCell;
}
public String getKwdikosNatura() {
return kwdikosNatura;
}
public void setKwdikosNatura(String kwdikosNatura) {
this.kwdikosNatura = kwdikosNatura;
}
public String getMethodosDeigmatolhpsias() {
return methodosDeigmatolhpsias;
}
public void setMethodosDeigmatolhpsias(String methodosDeigmatolhpsias) {
this.methodosDeigmatolhpsias = methodosDeigmatolhpsias;
}
public String getParathrhseis() {
return parathrhseis;
}
public void setParathrhseis(String parathrhseis) {
this.parathrhseis = parathrhseis;
}
public String getNomos() {
return nomos;
}
public void setNomos(String nomos) {
this.nomos = nomos;
}
public Byte getPicture() {
return picture;
}
public void setPicture(Byte picture) {
this.picture = picture;
}
public Byte getFile() {
return file;
}
public void setFile(Byte file) {
this.file = file;
}
}
Just to inform, adding a new CtThhlastikaPressThreats
is done successfully. 仅通知您,添加新的CtThhlastikaPressThreats
已成功完成。 Also the MySQL schema is created automatically on Run
. 另外,MySQL模式是在Run
自动创建的。
The project's github page is on https://github.com/alexgil1994/kerkinibackend 该项目的github页面位于https://github.com/alexgil1994/kerkinibackend
The Stack trace of the Error is ( and it keeps the same way recurcivelly, i didn't insert the whole stack because you can see already it repeats itself ) : 错误的堆栈跟踪为(并且递归地保持相同的方式,我没有插入整个堆栈,因为您已经看到它已经重复了):
2018-11-19 21:59:48.808 ERROR 1372 --- [nio-8080-exec-3] 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
java.lang.StackOverflowError: null
at org.springframework.data.repository.util.ClassUtils.unwrapReflectionException(ClassUtils.java:154) ~[spring-data-commons-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$ImplementationMethodExecutionInterceptor.invoke(RepositoryFactorySupport.java:646) ~[spring-data-commons-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.1.RELEASE.jar:5.1.1.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:608) ~[spring-data-commons-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$invoke$3(RepositoryFactorySupport.java:595) ~[spring-data-commons-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:595) ~[spring-data-commons-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.1.RELEASE.jar:5.1.1.RELEASE]
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59) ~[spring-data-commons-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.1.RELEASE.jar:5.1.1.RELEASE]
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294) ~[spring-tx-5.1.1.RELEASE.jar:5.1.1.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98) ~[spring-tx-5.1.1.RELEASE.jar:5.1.1.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.1.RELEASE.jar:5.1.1.RELEASE]
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139) ~[spring-tx-5.1.1.RELEASE.jar:5.1.1.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.1.RELEASE.jar:5.1.1.RELEASE]
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:117) ~[spring-data-jpa-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.1.RELEASE.jar:5.1.1.RELEASE]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93) ~[spring-aop-5.1.1.RELEASE.jar:5.1.1.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.1.RELEASE.jar:5.1.1.RELEASE]
at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61) ~[spring-data-commons-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.1.RELEASE.jar:5.1.1.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) ~[spring-aop-5.1.1.RELEASE.jar:5.1.1.RELEASE]
at com.sun.proxy.$Proxy112.findCtThhlastikaPressThreatsById(Unknown Source) ~[na:na]
at sun.reflect.GeneratedMethodAccessor63.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343) ~[spring-aop-5.1.1.RELEASE.jar:5.1.1.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:206) ~[spring-aop-5.1.1.RELEASE.jar:5.1.1.RELEASE]
at com.sun.proxy.$Proxy94.findCtThhlastikaPressThreatsById(Unknown Source) ~[na:na]
at com.teicm.kerkinibackend.repositories.CtThhlastikaPressThreatsRepositoryImpl.findCtThhlastikaPressThreatsById(CtThhlastikaPressThreatsRepositoryImpl.java:37) ~[classes/:na]
at com.teicm.kerkinibackend.repositories.CtThhlastikaPressThreatsRepositoryImpl$$FastClassBySpringCGLIB$$f23e415a.invoke(<generated>) ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.1.1.RELEASE.jar:5.1.1.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:746) ~[spring-aop-5.1.1.RELEASE.jar:5.1.1.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.1.1.RELEASE.jar:5.1.1.RELEASE]
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139) ~[spring-tx-5.1.1.RELEASE.jar:5.1.1.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.1.RELEASE.jar:5.1.1.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688) ~[spring-aop-5.1.1.RELEASE.jar:5.1.1.RELEASE]
at com.teicm.kerkinibackend.repositories.CtThhlastikaPressThreatsRepositoryImpl$$EnhancerBySpringCGLIB$$b6491b5e.findCtThhlastikaPressThreatsById(<generated>) ~[classes/:na]
at sun.reflect.GeneratedMethodAccessor64.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181]
at org.springframework.data.repository.core.support.RepositoryComposition$RepositoryFragments.invoke(RepositoryComposition.java:359) ~[spring-data-commons-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.data.repository.core.support.RepositoryComposition.invoke(RepositoryComposition.java:200) ~[spring-data-commons-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$ImplementationMethodExecutionInterceptor.invoke(RepositoryFactorySupport.java:644) ~[spring-data-commons-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.1.RELEASE.jar:5.1.1.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:608) ~[spring-data-commons-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$invoke$3(RepositoryFactorySupport.java:595) ~[spring-data-commons-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:595) ~[spring-data-commons-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.1.RELEASE.jar:5.1.1.RELEASE]
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59) ~[spring-data-commons-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.1.RELEASE.jar:5.1.1.RELEASE]
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294) ~[spring-tx-5.1.1.RELEASE.jar:5.1.1.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98) ~[spring-tx-5.1.1.RELEASE.jar:5.1.1.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.1.RELEASE.jar:5.1.1.RELEASE]
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139) ~[spring-tx-5.1.1.RELEASE.jar:5.1.1.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.1.RELEASE.jar:5.1.1.RELEASE]
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:117) ~[spring-data-jpa-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.1.RELEASE.jar:5.1.1.RELEASE]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93) ~[spring-aop-5.1.1.RELEASE.jar:5.1.1.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.1.RELEASE.jar:5.1.1.RELEASE]
at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61) ~[spring-data-commons-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.1.RELEASE.jar:5.1.1.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) ~[spring-aop-5.1.1.RELEASE.jar:5.1.1.RELEASE]
at com.sun.proxy.$Proxy112.findCtThhlastikaPressThreatsById(Unknown Source) ~[na:na]
at sun.reflect.GeneratedMethodAccessor63.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343) ~[spring-aop-5.1.1.RELEASE.jar:5.1.1.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:206) ~[spring-aop-5.1.1.RELEASE.jar:5.1.1.RELEASE]
at com.sun.proxy.$Proxy94.findCtThhlastikaPressThreatsById(Unknown Source) ~[na:na]
at com.teicm.kerkinibackend.repositories.CtThhlastikaPressThreatsRepositoryImpl.findCtThhlastikaPressThreatsById(CtThhlastikaPressThreatsRepositoryImpl.java:37) ~[classes/:na]
I apologize for any wrong-doings, the project is at the early stages of my Thesis. 对于任何不当行为,我深表歉意,该项目处于我论文的早期阶段。
Any help is really appreciated. 任何帮助都非常感谢。
Update - Solved: 更新-解决:
After following the suggestions in the answers the problem was solved. 遵循答案中的建议后,问题已解决。 There is farther explanation under the Correct Answer at one of my comments. 在我的评论之一的“正确答案”下还有更多解释。
Also if anyone is interested to see all the changes with details you can have a look at the commit that solved the problem at : 另外,如果有人有兴趣查看所有更改的详细信息,则可以在以下位置查看解决问题的提交:
https://github.com/alexgil1994/kerkinibackend/commit/230c1df96623363c61317216913b310c1c7ec231 https://github.com/alexgil1994/kerkinibackend/commit/230c1df96623363c61317216913b310c1c7ec231
I'd start by adding the following to you application.properties file so you can see exactly what sql statements are called. 首先,将以下内容添加到您的application.properties文件中,以便您可以准确地看到所调用的sql语句。
# Log sql statements and their parameters
logging.level.org.hibernate.SQL=debug
logging.level.org.hibernate.type.descriptor.sql=trace
@JsonIgnore won't help with reading the data. @JsonIgnore不会帮助您读取数据。 That only comes into when you're using Jackson to convert the objects to Json. 只有在使用Jackson将对象转换为Json时,才会出现这种情况。 ie when you return data from the RestController. 即当您从RestController返回数据时。
I just had a look at the ctThhlastikaPressThreatsRepository.findCtThhlastikaPressThreatsById method in the repo on github. 我只是在github上的仓库中查看了ctThhlastikaPressThreatsRepository.findCtThhlastikaPressThreatsById方法。 It appears to be calling itself, that'll cause the stack overflow. 它似乎正在自我调用,这将导致堆栈溢出。
public CtThhlastikaPressThreats findCtThhlastikaPressThreatsById(Long id){
try {
// TODO: 11/17/2018 !!! -- Try as an Optional findById(id) instead!!!
return ctThhlastikaPressThreatsRepository.findCtThhlastikaPressThreatsById(id);
}catch (Exception e){
throw e;
}
}
It's very confusing how you are using spring and jpa. 您如何使用spring和jpa非常令人困惑。 I would either use your own @Repository (the Impl version you have) or stick with the extending the CrudRepository. 我要么使用自己的@Repository(您拥有的Impl版本),要么坚持扩展CrudRepository。 Don't try and do both. 不要尝试同时做。
If you want to use the CrudRepository, all you need is to have something like you already have. 如果您想使用CrudRepository,您所需要的只是拥有已经拥有的东西。
public interface CtThhlastikaPressThreatsRepository extends CrudRepository<CtThhlastikaPressThreats, Long>, org.springframework.data.repository.Repository<CtThhlastikaPressThreats, Long> {
Optional<CtThhlastikaPressThreats> findById(Long id);
CtThhlastikaPressThreats findCtThhlastikaPressThreatsById(Long id);
@Query(nativeQuery = true, value = "SELECT DISTINCT ct.act_code FROM ct_thhlastika_press_threats ct ORDER BY act_code ASC")
ArrayList<String> findDistinctByActCodeOrderByActCode();
}
You should be able to remove the Impl version and just use this. 您应该能够删除Impl版本并使用它。
I'd suggest you write some test classes to make debugging easier. 我建议您编写一些测试类以使调试更容易。
eg 例如
@RunWith(SpringJUnit4ClassRunner.class)
@DataJpaTest
public class CtThhlastikaPressThreatsRepositoryImplTest {
@Autowired
private CtThhlastikaPressThreatsRepository ctThhlastikaPressThreatsRepository;
@Test
public void findByIdTest() {
CtThhlastikaPressThreats pressThreats = new CtThhlastikaPressThreats();
pressThreats.setActCode("actcode");
pressThreats.setDescriptionEn("description");
pressThreats.setRemarks("remarks");
ctThhlastikaPressThreatsRepository.save(pressThreats);
CtThhlastikaPressThreats found = ctThhlastikaPressThreatsRepository.findById(pressThreats.getId()).orElse(null);
assertEquals("description", found.getDescriptionEn());
CtThhlastikaPressThreats found2 = ctThhlastikaPressThreatsRepository.findCtThhlastikaPressThreatsById(pressThreats.getId());
assertEquals("description", found2.getDescriptionEn());
}
@Test
public void listCodesTest() {
CtThhlastikaPressThreats pressThreats = new CtThhlastikaPressThreats();
pressThreats.setActCode("actcode1");
pressThreats.setDescriptionEn("description1");
pressThreats.setRemarks("remarks1");
ctThhlastikaPressThreatsRepository.save(pressThreats);
pressThreats = new CtThhlastikaPressThreats();
pressThreats.setActCode("actcode2");
pressThreats.setDescriptionEn("description2");
pressThreats.setRemarks("remarks2");
ctThhlastikaPressThreatsRepository.save(pressThreats);
List<String> expected = Arrays.asList(new String[] {"actcode1", "actcode2"});
ArrayList<String> found = ctThhlastikaPressThreatsRepository.findDistinctByActCodeOrderByActCode();
assertTrue(found.containsAll(expected) && expected.containsAll(found));
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.