Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate envers交叉引用无限循环堆栈溢出问题_Hibernate_Jpa - Fatal编程技术网

Hibernate envers交叉引用无限循环堆栈溢出问题

Hibernate envers交叉引用无限循环堆栈溢出问题,hibernate,jpa,Hibernate,Jpa,类“quote”和类“Item”与类“QuotationJoinItem”相关。 它们都带有“@Audited”注释,以便管理实体变更日志。 但当我试图通过特定id获得“Quotence”的修订时,Quotence和QuoteationJoinItem相互调用为无限。你能介绍一些解决办法吗 quote.kt @Entity(name = "quotation") @Audited data class Quotation ( //... some other fields ...

类“quote”和类“Item”与类“QuotationJoinItem”相关。 它们都带有“@Audited”注释,以便管理实体变更日志。 但当我试图通过特定id获得“Quotence”的修订时,Quotence和QuoteationJoinItem相互调用为无限。你能介绍一些解决办法吗

quote.kt

@Entity(name = "quotation")
@Audited
data class Quotation (
    //... some other fields ...

        @OneToMany(mappedBy = "quotation", cascade = [CascadeType.PERSIST])
        @AuditMappedBy(mappedBy ="quotation")
        var items: MutableList<QuotationJoinItem>? = null

): BaseEntity(), Serializable
@Entity("quotation_join_item")
@Audited
data class QuotationJoinItem (
    // ... some other fields

        @ManyToOne
        @JsonBackReference
        @JoinColumn(name="quotation_id")
        var quotation: Quotation,

        @ManyToOne
        @JoinColumn(name="item_id")
        @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
        var item: Item,

):BaseEntity(), Serializable
@Entity(name="item")
data class Item(
    //... It has no reference about Quotation or QuotationJoinItem table.
): BaseEntity(), Serializable
@Repository
interface QuotationRepository: JpaRepository<Quotation, Int>, QuotationRepositoryCustom, RevisionRepository<Quotation, Int, Int>{
    //some other funtion
}

@Service
class QuotationService (
    // some other arguments of constructor

    private val quotationRepository: QuotationRepository 
){

}
    // some other function

    @Transactional
    fun findRevision(id: Int): Revisions<Int, Quotation> {
        return quotationRepository.findRevisions(id) //!!problem occured here.
    }
Item.kt

@Entity(name = "quotation")
@Audited
data class Quotation (
    //... some other fields ...

        @OneToMany(mappedBy = "quotation", cascade = [CascadeType.PERSIST])
        @AuditMappedBy(mappedBy ="quotation")
        var items: MutableList<QuotationJoinItem>? = null

): BaseEntity(), Serializable
@Entity("quotation_join_item")
@Audited
data class QuotationJoinItem (
    // ... some other fields

        @ManyToOne
        @JsonBackReference
        @JoinColumn(name="quotation_id")
        var quotation: Quotation,

        @ManyToOne
        @JoinColumn(name="item_id")
        @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
        var item: Item,

):BaseEntity(), Serializable
@Entity(name="item")
data class Item(
    //... It has no reference about Quotation or QuotationJoinItem table.
): BaseEntity(), Serializable
@Repository
interface QuotationRepository: JpaRepository<Quotation, Int>, QuotationRepositoryCustom, RevisionRepository<Quotation, Int, Int>{
    //some other funtion
}

@Service
class QuotationService (
    // some other arguments of constructor

    private val quotationRepository: QuotationRepository 
){

}
    // some other function

    @Transactional
    fun findRevision(id: Int): Revisions<Int, Quotation> {
        return quotationRepository.findRevisions(id) //!!problem occured here.
    }
通过属性[QUOTE\U AUD][QUOTE\U join\U item\U AUD]表生成

应用程序属性

# other configuration

spring.jpa.hibernate.ddl-auto=update

插入逻辑运行良好。 每个*AUD表都有自己的日志(历史记录)

但,当我试图按照下面的过程检索日志数据时,出现了问题

QuotationRepository.kt

@Entity(name = "quotation")
@Audited
data class Quotation (
    //... some other fields ...

        @OneToMany(mappedBy = "quotation", cascade = [CascadeType.PERSIST])
        @AuditMappedBy(mappedBy ="quotation")
        var items: MutableList<QuotationJoinItem>? = null

): BaseEntity(), Serializable
@Entity("quotation_join_item")
@Audited
data class QuotationJoinItem (
    // ... some other fields

        @ManyToOne
        @JsonBackReference
        @JoinColumn(name="quotation_id")
        var quotation: Quotation,

        @ManyToOne
        @JoinColumn(name="item_id")
        @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
        var item: Item,

):BaseEntity(), Serializable
@Entity(name="item")
data class Item(
    //... It has no reference about Quotation or QuotationJoinItem table.
): BaseEntity(), Serializable
@Repository
interface QuotationRepository: JpaRepository<Quotation, Int>, QuotationRepositoryCustom, RevisionRepository<Quotation, Int, Int>{
    //some other funtion
}

@Service
class QuotationService (
    // some other arguments of constructor

    private val quotationRepository: QuotationRepository 
){

}
    // some other function

    @Transactional
    fun findRevision(id: Int): Revisions<Int, Quotation> {
        return quotationRepository.findRevisions(id) //!!problem occured here.
    }
谢谢你检查这个问题。虽然它的英语很差,但是非常感谢你的关心

已经解决了

我使用“数据类”作为实体。 这就是问题所在

它会自动覆盖
hashCode()
方法

“Quotence”类的哈希代码引用了“QuoteationJoinItem”。然后,“QuotationJoinItem”类的哈希代码引用“Quotion”。通过这种方式,它们相互引用

有两种解决办法

解决方案1。 我刚刚从实体的“数据类”中删除了“数据”关键字

解决方案2。 我将@OneToMany变量(在这个问题中为“items”)移动到字段而不是构造函数


请参考我同事的问题。谢谢

你能粘贴整个地图吗<代码>@OneToMany(mappedBy=“quote”)未在中重新显示child@Andronicus我很抱歉。我犯了一个错误。我更新了问题的源代码。你能再检查一下吗?他们需要更多的信息吗?嗨,我遇到了同样的问题,但是在我的实体中,当我删除Public word时,我使用了“Public Class EntityName”,另一个类无法访问我的实体类,我该怎么办?感谢访问并留下您对这个问题的评论。看来你已经从另一个问题中得到了答案。所以我把你的问题链接到这里。对那些遭受同样问题折磨的人。谢谢你帮助我得到提升。