How to map a composite key with JPA and Hibernate?

前端 未结 8 1253
旧时难觅i
旧时难觅i 2020-11-22 10:37

In this code, how to generate a Java class for the composite key (how to composite key in hibernate):

create table Time (
     levelStation int(15) not null,         


        
8条回答
  •  执笔经年
    2020-11-22 10:59

    You need to use @EmbeddedId:

    @Entity
    class Time {
        @EmbeddedId
        TimeId id;
    
        String src;
        String dst;
        Integer distance;
        Integer price;
    }
    
    @Embeddable
    class TimeId implements Serializable {
        Integer levelStation;
        Integer confPathID;
    }
    

提交回复
热议问题