如何在 Hibernate 中加载 Child Object

How to Load Child Object in Hibernate

如何在加载 Parent Object (DuaVO) object.[=16= 时加载 child object (RefAuthorizationVO) ]

主要Class加载方法

DuaVO dua = (DuaVO) session.get(DuaVO.class, "1");

RefAuthorization Child

@Entity
@Table(name = "RFRNC_AUTHRZTN")
public class RefAuthorizationVO implements Serializable
{
    @Column(name = "SYS_CREAT_USER_ID")
    private String sysCreatedUserId;

    @Column(name = "SYS_CREAT_TS")
    private Date sysCreatedTimestamp;

    @Column(name = "SYS_UPDT_USER_ID")
    private String sysUpdateUserId;

    @Column(name = "SYS_UPDT_TS")
    private Date sysUpdateTimestamp;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name="AUTHRZTN_CD")
    private String authorizationCode;

    @Column(name="AUTHRZTN_DESC")
    private String authorizationDescription;

DuaVO Parent

@Entity
@Table(name = "DUA")
public class DuaVO implements java.io.Serializable {

    @Id
    @Column(name= "DUA_NUM")
    private String duaNumber;

    // AuditDetails

    @Column(name = "SYS_CREAT_USER_ID")
    private String sysCreatedUserId;

    @Column(name = "SYS_CREAT_TS")
    private Date sysCreatedTimestamp;

    @Column(name = "SYS_UPDT_USER_ID")
    private String sysUpdateUserId;

    @Column(name = "SYS_UPDT_TS")
    private Date sysUpdateTimestamp;

    @Column(name = "DUA_SHRT_DESC")
    private String duaShortDesc;

    @Column(name = "AUTHRZTN_CD")
    private String authorizationCode;

    @ManyToOne
    private RefAuthorizationVO refAuthorizationVO; 

    }

但是,当我尝试像这样访问 child 时..

System.out.println("Ref Auth: " + dua.getRefAuthorizationVO() );

我得到空值。

认为您错过了@JoinColumn 注释

@JoinColumn(name = "FK_ID", referencedColumnName = "ID")
@ManyToOne