V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
qiyong
V2EX  ›  问与答

求助! JPA 多表关联生成 sql 表别名重复问题

  •  
  •   qiyong · 2023-03-17 10:29:13 +08:00 · 729 次点击
    这是一个创建于 643 天前的主题,其中的信息可能已经有所发展或是发生改变。

    使用 JPA 多表关联注解 ManyToOne ,之类的写功能的时候,生成了这样一个 sql ,表别名是重复的,不知道为什么, 以下是片段,可以看出 tmpaymentsettlement 和 TMPAYMENTSETTLEMENTBILL 的别名是一样的,导致报错,不知道为什么,请大神解答

    from tmpaymentsettlement tmpayments0_ left outer join TMPAYMENTSETTLEMENTBILL tmpayments0_ on tmpayments0_.ID=tmpayments0_.PAYMENTSETTLEMENTID left outer join TMPAYMENTSETTLEMENTDETAIL tmpayments1_ on tmpayments0_.ID=tmpayments1_.PAYMENTSETTLEMENTID left outer join TMPAYMENTSETTLEMENTTYPE tmpayments2_
    

    附上部分表关系

    @Table(name = "TMPAYMENTSETTLEMENT")
    public class Tmpaymentsettlement implements Serializable {
        XXX……
        
        @OneToOne(mappedBy = "tmpaymentsettlement", orphanRemoval = true, fetch = FetchType.EAGER)
        @NotFound(action= NotFoundAction.IGNORE)
        @JSONField(name = "TMPAYTVERIFICATTIONREL")
        private TmpaytverificattionrelC2 tmpaytverificattionrel;
    
        @OneToOne(mappedBy = "tmpaymentsettlement", orphanRemoval = true, fetch = FetchType.EAGER)
        @NotFound(action= NotFoundAction.IGNORE)
        @JSONField(name = "BPSETTLEMENTANDRECEIPT")
        private BpsettlementandreceiptC2 bpsettlementandreceipt;
    
        @OneToMany(fetch = FetchType.EAGER)
        @NotFound(action= NotFoundAction.IGNORE)
        @JoinColumn(name = "PAYMENTSETTLEMENTID", referencedColumnName = "ID")
        @JSONField(name = "TMPAYMENTSETTLEMENTDETAIL")
        private Set<TmpaymentsettlementdetailC2> tmpaymentsettlementdetail;
    
        @OneToMany(fetch = FetchType.EAGER)
        @NotFound(action= NotFoundAction.IGNORE)
        @JoinColumn(name = "PAYMENTSETTLEMENTID", referencedColumnName = "ID")
        @JSONField(name = "TMPAYMENTSETTLEMENTTYPE")
        private Set<TmpaymentsettlementtypeC2> tmpaymentsettlementtype;
    
        @OneToMany(fetch = FetchType.EAGER)
        @NotFound(action= NotFoundAction.IGNORE)
        @JoinColumn(name = "PAYMENTSETTLEMENTID", referencedColumnName = "ID")
        @JSONField(name = "TMPAYMENTSETTLEMENTBILL")
        private Set<TmpaymentsettlementbillC2> tmpaymentsettlementbill;
            
    }
    
    @Table(name = "TMPAYMENTSETTLEMENTBILL")
    这个表中没有关联 只有他本身的字段
    
     @NamedEntityGraph(
     ……
     @NamedSubgraph(name = "bpbizpaytreqpaytexectrecd", attributeNodes = @NamedAttributeNode(value ="tmjsxx", subgraph = "tmjsxx")),//四级延伸
                    @NamedSubgraph(name = "tmjsxx", attributeNodes = {
                            @NamedAttributeNode(value = "tmpaymentsettlement", subgraph = "tmpaymentsettlement"),
                            @NamedAttributeNode(value = "tmbillendorserequest", subgraph = "tmbillendorserequest"),
                            @NamedAttributeNode(value = "tmbillingrequest", subgraph = "tmbillingrequest"),
                            @NamedAttributeNode(value = "tmbillpayablerequest", subgraph = "tmbillpayablerequest")
    
                    }),//五级延伸
                    @NamedSubgraph(name = "tmpaymentsettlement", attributeNodes = {
                            @NamedAttributeNode(value = "tmpaytverificattionrel"),
                            @NamedAttributeNode(value = "bpsettlementandreceipt", subgraph = "bpsettlementandreceipt"),
                            @NamedAttributeNode(value = "tmpaymentsettlementdetail"),
                            @NamedAttributeNode(value = "tmpaymentsettlementtype"),
                            @NamedAttributeNode(value = "tmpaymentsettlementbill")
                    }),//五级延伸
                    ……}
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3553 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 04:30 · PVG 12:30 · LAX 20:30 · JFK 23:30
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.