Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Hibernate 6.5, how to set mapping between entities with partial composite primary key

Eric ZuoAug 9 2024

Hello Experts,
I understand ManyToMany, ManyToOne, OneToMany in database table relationship.
but still confused in setting fields to associate entities with composite (whole or partial) primary keys. I am stopped in days by this problem.
In the following 3 entities, each has a collection of another entity, I have difficulty to add the association.
Please find my questions for the connection in each of the entities. I deleted some fields to short the post.
Entity 1

@Table(name = "MRS_CON_HIST")
@Entity
public class MrsConHist { 
    @EmbeddedId
    private MrsConHistPK comp_id;
    @Column(name = "DATETIME_OUTSRV")
    private Date datetimeOutsrv;    
    @Column(name = "RUN_TIME_HRS")
    private int runTimeHrs;
    @Column(name = "RUN_TIME_MIN")
    private int runTimeMin;
    @Column(name = "CON_STAT")
    private String conStat;
    //How to set the association here:
    private Set<MrsVehIncd> mrsVehIncds = new HashSet<MrsVehIncd>(0);
    // functions skipped
}
*Key of Entity 1*
@Embeddable
public class MrsConHistPK  implements java.io.Serializable {
    private static final long serialVersionUID = 1L;
    @Column(name = "CAN_NO")
    private String conNo;
    @Column(name = "DASH_NO")
    private Integer dashNo;
    @Column(name = "DATE_INSRV_REV")
    private java.util.Date dateInsrvRev;
    @Column(name = "DATETIME_INSRV")
    private Date datetimeInsrv;
    // functions skipped
}

Entity 2.

@Table(name = "MRS_VEH_INCD")
@Entity
public class MrsVehIncd {   
private static final long serialVersionUID = 1L;
    @Column(name = "INCD_NO") 
    @Id
    private String incdNo;          //primary key,  also has the 4 fields of MrsConHistPK,
    @Column(name = "VEH_INCD_STAT")
    private String vehIncdStat;
    @Column(name = "CAN_NO")
    private String conNo;
    @Column(name = "DASH_NO")
    private Integer dashNo;
    @Column(name = "WORK_TYPE")
    private Integer workType;
    @Column(name = "DATE_INSRV_REV")
    private java.util.Date dateInsrvRev;
    @Column(name = "DATETIME_INSRV")
    private Date datetimeInsrv;
    //How to set the association here:
    private Set<MrsConHist > MrsConHists = new HashSet<MrsConHist >(0);
    // functions skipped
}

Entity 3.

@Table(name = MRS_VEH_INCDHEX)
@Entity
public class MrsVehIncdHex {  
    @EmbeddedId
    private MrsConHistHexPK comp_id;
     @Column(name = "DATE_INSRV_REV")
    private java.util.Date dateInsrvRev;
    ......
    //How to set the association here:
    private Set<MrsConHist > MrsConHists_Hex = new HashSet<MrsConHist >(0);
    // functions skipped
}

Key of Entity 3 // it has part of the key fields in the entities 1. and 2. above.

@Embeddable
public class MrsVehIncdHexPK  implements java.io.Serializable {
    private static final long serialVersionUID = 1L;
    @Column(name = "CON_NO")
    private String conNo;
    @Column(name = "INCD_NO")
    private String incdNo;
    @Column(name = "VTDCODE")
    private String vtdCode;
    // functions skipped
}

In case you could spare some time, please help.
Thank you,
Eric

Comments

Arnoschots-Oracle Apr 22 2020 — edited on Apr 22 2020

Hi,

The "sudo al-config -s" doesn't work on my Autonomous Linux instance.

Command output:

[opc@opsserver ~]$ sudo al-config -s

/sbin/al-config: illegal option -- s

Configure OCI notification service topic OCID:

  Usage:

    al-config -T [topic OCID]

  Options:

    -T [topic OCID] OCI notification service topic OCID

Configure OCI CLI profile:

  Usage:

    al-config -u [user OCID] -t [tenancy OCID] -k [key file]

  Options:

    -u [user OCID] OCI User OCID

    -t [tenancy OCID] OCI Tenancy OCID

    -k [key file] from which we obtaion the API private key

    -p [key passphrase file] from which we obtain API key passphrase. Provide

       this if API private key is encrypted. If not provided, user will be

       prompted to enter passphrase.

1 - 1

Post Details

Added on Aug 9 2024
0 comments
106 views