gpt4 book ai didi

java - hibernate enver findRevisions hashCode StackOverflowError

转载 作者:行者123 更新时间:2023-12-01 19:05:44 28 4
gpt4 key购买 nike

我尝试使用 enver 作为 kotlin。

我只是想运行下面的代码。


@Transactional
fun findOrderDraftHistory(id: Int, @PageableDefault(page = 0, size = 10, sort = ["rev#DESC"]) pageable: Pageable): Page<Revision<Int, OrderDraft>> {
return orderDraftRepository.findRevisions(id, pageable)
}

但是我遇到了一个错误。我不明白为什么。有解决办法吗?如果您需要什么,请告诉我。

该语言使用 kotlin。db语言使用mysql。

创建表

CREATE TABLE `order_draft` (
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`order_number` VARCHAR(255) NOT NULL,
`order_type` ENUM('OUTER','INNER') NOT NULL,
`seller` VARCHAR(255) NOT NULL,
`seller_manager` VARCHAR(255) NULL DEFAULT NULL,
`seller_manager_phone` VARCHAR(255) NULL DEFAULT NULL,
`sign1` INT(11) UNSIGNED NOT NULL,
`sign2` INT(11) UNSIGNED NOT NULL,
`project_name` VARCHAR(255) NOT NULL,
`delivery_date` DATETIME NOT NULL,
`reference` VARCHAR(255) NULL DEFAULT NULL,
`total_price` INT(11) NOT NULL,
`approval_request` BIT(1) NOT NULL DEFAULT b'0',
`approval_request_date` DATETIME NULL DEFAULT NULL,
`approved` BIT(1) NOT NULL DEFAULT b'0' ,
`sign_off_on` INT(11) NULL DEFAULT NULL ,
`signed_datetime` DATETIME NULL DEFAULT NULL,
`returned` BIT(1) NOT NULL DEFAULT b'0',
`returned_reason` VARCHAR(255) NULL DEFAULT NULL,
`delivered` BIT(1) NOT NULL DEFAULT b'0',
`delivered_sign` INT(11) UNSIGNED NULL DEFAULT NULL,
`delivered_date` DATETIME NULL DEFAULT NULL,
`termination` BIT(1) NOT NULL DEFAULT b'0' ,
`termination_sign` INT(11) UNSIGNED NULL DEFAULT NULL,
`termination_date` DATETIME NULL DEFAULT NULL,
`used` BIT(1) NOT NULL DEFAULT b'1',
`creator` INT(11) UNSIGNED NOT NULL,
`updator` INT(11) UNSIGNED NULL DEFAULT NULL,
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
;
CREATE TABLE `order_draft_join_item` (
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`item_id` INT(11) UNSIGNED NULL DEFAULT NULL,
`order_draft_id` INT(11) UNSIGNED NULL DEFAULT NULL,
`item_code_full` VARCHAR(255) NOT NULL,
`item_name` VARCHAR(255) NOT NULL,
`standard_size` VARCHAR(255) NOT NULL,
`amount` INT(11) NOT NULL,
`unit_name` VARCHAR(255) NOT NULL,
`unit_price` INT(11) NOT NULL,
`supply_value` INT(11) NOT NULL,
`vat` INT(11) NOT NULL,
`total_price` INT(11) NOT NULL,
`remark` VARCHAR(255) NOT NULL DEFAULT '',
`creator` INT(11) UNSIGNED NOT NULL,
`updator` INT(11) UNSIGNED NULL DEFAULT NULL,
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
;

错误日志


org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.StackOverflowError
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1054)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:897)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:320)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:119)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:170)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:74)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:109)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:109)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:215)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:178)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:357)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:270)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:109)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:92)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:109)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:109)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:109)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:853)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1587)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.StackOverflowError
at com.myproject.test.model.User.hashCode(User.kt)
at com.myproject.test.model.OrderDraft.hashCode(OrderDraft.kt)
at com.myproject.test.model.OrderDraftJoinItem.hashCode(OrderDraftJoinItem.kt)
at java.util.AbstractList.hashCode(AbstractList.java:541)
at org.hibernate.envers.internal.entities.mapper.relation.lazy.proxy.CollectionProxy.hashCode(CollectionProxy.java:131)
at com.myproject.test.model.OrderDraft.hashCode(OrderDraft.kt)
at com.myproject.test.model.OrderDraftJoinItem.hashCode(OrderDraftJoinItem.kt)
at java.util.AbstractList.hashCode(AbstractList.java:541)
at org.hibernate.envers.internal.entities.mapper.relation.lazy.proxy.CollectionProxy.hashCode(CollectionProxy.java:131)
at com.myproject.test.model.OrderDraft.hashCode(OrderDraft.kt)
at com.myproject.test.model.OrderDraftJoinItem.hashCode(OrderDraftJoinItem.kt)
at java.util.AbstractList.hashCode(AbstractList.java:541)
2020-01-02 14:57:29.510 ERROR 21040 --- [nio-8080-exec-8] Exception Handler : kotlin.Unit


模型代码 - order_draft


import org.hibernate.annotations.NotFound
import org.hibernate.annotations.NotFoundAction
import org.hibernate.envers.Audited
import org.hibernate.envers.RelationTargetAuditMode
import java.io.Serializable
import java.time.LocalDateTime
import javax.persistence.*

enum class EOrderType (orderType: String) {
INNER ("INNER"),
OUTER ("OUTER")
}

@Audited
@Entity(name="order_draft")
data class OrderDraft(
@Column(name = "order_number")
val orderNumber: String,
@Enumerated(EnumType.STRING)
@Column(name = "order_type")
@NotFound(action = NotFoundAction.IGNORE)
val orderType: EOrderType,
@Column
var seller: String,
@Column(name = "seller_manager")
var sellerManager: String,
@Column(name = "seller_manager_phone")
var sellerManagerPhone: String,
@Column(name = "project_name")
var projectName: String,
@Column(name = "delivery_date")
var deliveryDate: String,
@Column
var reference: String,
@Column(name = "total_price")
var totalPrice: Int,
@ManyToOne
@JoinColumn(name = "sign1")
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
@NotFound(action = NotFoundAction.IGNORE)
var sign1: User,
@ManyToOne
@JoinColumn(name = "sign2")
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
@NotFound(action = NotFoundAction.IGNORE)
var sign2: User,
@Column(name = "approval_request")
var approvalRequest: Boolean = false,
@Column(name = "approval_request_date")
var approvalRequestDate: LocalDateTime? = null,
@ManyToOne
@JoinColumn(name="sign_off_on")
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
@NotFound(action = NotFoundAction.IGNORE)
var signOffOn: User? = null,
@Column
var approved: Boolean = false,
@Column(name = "signed_datetime")
var signedDatetime: LocalDateTime? = null,
@Column
var returned: Boolean = false,
@Column(name="returned_reason")
var returnedReason: String? = null,
@Column
var delivered: Boolean,
@ManyToOne
@JoinColumn(name="delivered_sign")
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
@NotFound(action = NotFoundAction.IGNORE)
var deliveredSign: User? = null,
@Column(name="delivered_date")
var deliveredDate: LocalDateTime? = null,
@Column
var termination: Boolean,
@ManyToOne
@JoinColumn(name="termination_sign")
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
@NotFound(action = NotFoundAction.IGNORE)
var terminationSign: User? = null,
@Column(name="termination_date")
var terminationDate: LocalDateTime? = null,
@Column
var used: Boolean = true,
@OneToMany
@JoinTable(name = "order_draft_join_attachment")
@NotFound(action = NotFoundAction.IGNORE)
var attachment: List<Attachment>? = null,
@OneToMany(mappedBy = "orderDraft")
@NotFound(action = NotFoundAction.IGNORE)
val orderDraftItem: MutableList<OrderDraftJoinItem>? = null
)

模型代码 - orderDraftJoinItem


import com.fasterxml.jackson.annotation.JsonBackReference
import org.hibernate.annotations.NotFound
import org.hibernate.annotations.NotFoundAction
import org.hibernate.envers.Audited
import org.hibernate.envers.RelationTargetAuditMode
import org.springframework.data.annotation.ReadOnlyProperty
import java.io.Serializable
import javax.persistence.*

@Audited
@Entity(name="order_draft_join_item")
data class OrderDraftJoinItem (
@JsonBackReference
@ManyToOne
@JoinColumn(name="order_draft_id")
@NotFound(action = NotFoundAction.IGNORE)
val orderDraft : OrderDraft,
@ManyToOne
@JoinColumn(name="item_id")
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
@NotFound(action = NotFoundAction.IGNORE)
val item: Item,
@Column(name="item_code_full")
val itemCodeFull: String,
@Column(name="item_name")
val itemName: String,
val standardSize: String,
val amount: Int,
@Column(name="unit_name")
val unitName: String,
@Column(name="unit_price")
val unitPrice: Int,
@Column(name="supply_value")
val supplyValue: Int,
val vat: Int,
@Column(name="total_price")
val totalPrice: Int,
val remark: String,
@ReadOnlyProperty
@OneToMany
@JoinTable(name="order_draft_join_item_join_attachment")
@NotFound(action = NotFoundAction.IGNORE)
var attachment: List<Attachment>? = null
)

orderDraftRepository接口(interface)

interface OrderDraftRepository : JpaRepository<OrderDraft, Int>, OrderDraftRepositoryCustom, RevisionRepository<OrderDraft, Int, Int> {
}

最佳答案

停止为您的实体使用数据类。使用常规类(class)。

数据类的 hashCode()equals()toString() 使用构造函数中声明的所有属性,并且这当然会导致循环引用的堆栈溢出。

关于java - hibernate enver findRevisions hashCode StackOverflowError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59558988/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com