日期:2014-05-19 浏览次数:20830 次
@Entity @Table(name = "card_info") public class CardInfo { @GenericGenerator(name = "uuid", strategy = "com.hibernate.my.UUIDGenerator") @GeneratedValue(generator = "uuid") @Column(name = "card_id") @Id private String cardId; @Column(name = "card_user_name") private String cardUserName; @Column(name = "card_code") //这个键是唯一约束键,意思是“卡片编号” private String cardCode; //setter getter省略 }
@Entity @Table(name = "card_data") public class CardData { @GenericGenerator(name = "uuid", strategy = "com.hibernate.my.UUIDGenerator") @GeneratedValue(generator = "uuid") @Column(name = "card_data_id") @Id private String cardDataId; @Column(name = "create_time") private Date createTime; //刷卡时间 @Column(name = "card_code") //这个键是唯一约束键,意思是“卡片编号” private String cardCode; @ManyToOne(fetch = FetchType.LAZY) @Cascade(value = { org.hibernate.annotations.CascadeType.SAVE_UPDATE }) @JoinColumn(name = "card_code", insertable = false, updatable = false, unique = true) private CardInfo cardInfo; //setter getter省略
select * from card_data data inner join card_info info on data.card_code=info.card_id
select * from card_data data inner join card_info info on data.card_code=info.card_code --这里是两个表的card_code进行匹配