Duplicate columns when using EmbeddedId with a ManyToOne mapping with Ebean

后端 未结 2 1983
暖寄归人
暖寄归人 2021-02-19 09:52

I have a model called \"EventCheckin\" which has a ManyToOne mapping to an \"Event\" and a \"User\". The PrimaryKey of the \"EventCheckin\" table is the id of the user and the i

2条回答
  •  生来不讨喜
    2021-02-19 10:56

    It looks like you try to do same thing via @MapsId and @EmbeddedId. One (working) option is to go for IdClass (equals, hashcode, extra attributes etc are cut away):

        @Entity
        public class User {
            @Id public String id;
        }
    
        @Entity
        public class Event {
            @Id public long id;
        }
    
        public class CheckinId implements Serializable {
            public Long event;
            public String user;
        }
    
        @Entity
        @IdClass(CheckinId.class)
        @Table(name="eventCheckin")
        public class EventCheckin {
    
            @Id
            @JoinColumn(name="user_id")
            @ManyToOne public User user;
    
            @Id
            @JoinColumn(name="event_id")
            @ManyToOne public Event event;
        }
    

提交回复
热议问题