jpaフレームワークを使用してデータベースに接続するjavaアプリケーションがあります。 オブジェクトUserInformation
にAdditionData
オブジェクトが含まれていると、userInformationRepository.findByUserId(id)
エラーが発生します。データベースからデータをロードするときにStackOverflowErrorが発生しました
>java.lang.StackOverflowError: null
Method threw 'java.lang.StackOverflowError' exception. Cannot evaluate com.entity.UserInformation.toString()
java.lang.StackOverflowError: null
at javax.servlet.ServletResponseWrapper.getBufferSize(ServletResponseWrapper.java:167) ~[tomcat-embed-core-8.5.6.jar:8.5.6]
at javax.servlet.ServletResponseWrapper.getBufferSize(ServletResponseWrapper.java:167) ~[tomcat-embed-core-8.5.6.jar:8.5.6]
at org.springframework.security.web.util.OnCommittedResponseWrapper.checkContentLength(OnCommittedResponseWrapper.java:232) ~[spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.security.web.util.OnCommittedResponseWrapper.access$200(OnCommittedResponseWrapper.java:33) ~[spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.security.web.util.OnCommittedResponseWrapper$SaveContextServletOutputStream.write(OnCommittedResponseWrapper.java:637) ~[spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at com.fasterxml.jackson.core.json.UTF8JsonGenerator._flushBuffer(UTF8JsonGenerator.java:2033) ~[jackson-core-2.8.4.jar:2.8.4]
at com.fasterxml.jackson.core.json.UTF8JsonGenerator.writeRaw(UTF8JsonGenerator.java:632) ~[jackson-core-2.8.4.jar:2.8.4]
at com.fasterxml.jackson.core.json.UTF8JsonGenerator.writeRaw(UTF8JsonGenerator.java:555) ~[jackson-core-2.8.4.jar:2.8.4]
at com.fasterxml.jackson.core.json.UTF8JsonGenerator.writeNumber(UTF8JsonGenerator.java:931) ~[jackson-core-2.8.4.jar:2.8.4]
at com.fasterxml.jackson.databind.ser.std.NumberSerializers$FloatSerializer.serialize(NumberSerializers.java:194) ~[jackson-databind-2.8.4.jar:2.8.4]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:704) ~[jackson-databind-2.8.4.jar:2.8.4]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:690) ~[jackson-databind-2.8.4.jar:2.8.4]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155) ~[jackson-databind-2.8.4.jar:2.8.4]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:704) ~[jackson-databind-2.8.4.jar:2.8.4]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:690) ~[jackson-databind-2.8.4.jar:2.8.4]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155) ~[jackson-databind-2.8.4.jar:2.8.4]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:704) ~[jackson-databind-2.8.4.jar:2.8.4]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:690) ~[jackson-databind-2.8.4.jar:2.8.4]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155) ~[jackson-databind-2.8.4.jar:2.8.4]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:704) ~[jackson-databind-2.8.4.jar:2.8.4]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:690) ~[jackson-databind-2.8.4.jar:2.8.4]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155) ~[jackson-databind-2.8.4.jar:2.8.4]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:704) ~[jackson-databind-2.8.4.jar:2.8.4]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:690) ~[jackson-databind-2.8.4.jar:2.8.4]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155) ~[jackson-databind-2.8.4.jar:2.8.4]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:704) ~[jackson-databind-2.8.4.jar:2.8.4]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:690) ~[jackson-databind-2.8.4.jar:2.8.4]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155) ~[jackson-databind-2.8.4.jar:2.8.4]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:704) ~[jackson-databind-2.8.4.jar:2.8.4]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:690) ~[jackson-databind-2.8.4.jar:2.8.4]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155) ~[jackson-databind-2.8.4.jar:2.8.4]
ユーザ情報エンティティ
@Data
@Entity(name = "user_information")
public class UserInformation {
@Id
@Column(name = "uuid")
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name = "user_id")
private Long userId;
@Column(name = "title", length = 64)
private String title;
@Column(name = "message", length = 128)
private String message;
@OneToOne(mappedBy = "userInformation")
private AdditionData additionData;
}
AdditionDataエンティティ
:応答で は、私は多くの内側のオブジェクトuserInformation->additionData->userInformation->userInformation->additionData->userInformation->....
例外でJSONを見ます
リポジトリエンティティUserInformation
ため
@Repository
public interface UserInformationRepository extends CrudRepository<UserInformation, Long> {
List<UserInformation> findByIdIn(List<Long> ids);
UserInformation findByUserId(Long userId);
}
は、エラーが発生したのはなぜ?エンティティ内の関係の設定にエラーがありますか?
これらのエンティティで 'toString()'メソッドをオーバーライドしましたか? –