我的表格结构如下:
Table Campaign{ Camp_id(PK), other columns... } Table User{ user_id(PK), other columns... } Table Candidate{ cand_id(PK), other columns... } Table Result{ user_id(PK), camp_id(PK), cand_id }
sf6xfgos1#
试着这样做:实体表格活动
@Entity @Table(name="CAMPAIGN") public class Campaign implements Serializable { @GeneratedValue(...) @Id @Column(name="CAMP_ID") Long campId .... }
实体用户
@Entity @Table(name="USER") public class User implements Serializable { @GeneratedValue(...) @Id @Column(name="USER_ID") Long userId .... }
实体候选人
@Entity @Table(name="CANDIDATE") public class Candidate implements Serializable { @GeneratedValue(...) @Id @Column(name="CAND_ID") Long candId .... }
实体结果
@Entity @Table(name="RESULT") public class Result implements Serializable { @EmbeddedId private ResultId id; @ManyToOne @JoinColumn(name = "CAND_ID") private Candidate candidate; ... } @Embeddable public class ResultId implements Serializable { @ManyToOne @JoinColumn(name = "USER_ID") private User user; @ManyToOne @JoinColumn(name = "CAMP_ID") private Campaign campaign; }
1条答案
按热度按时间sf6xfgos1#
试着这样做:
实体表格活动
实体用户
实体候选人
实体结果