代理商和卡的关系,一对多
@Table("card")
public class Card {
@Id
private int id;
@Column("card_no")
private int cardNo;
@Column("password")
private String password;
@Column("agent_id")
private int agentId;
...get和set方法
}
@Table("agent")
public class Agent {
@Id
private int id;
@Column
private String username;
@Column
private String password;
@Many(target = Card.class, field = "agentId")
private List<Card> cards;
...get和set方法
}
执行后的建表语句如下:
CREATE TABLE agent(
id SERIAL,
username VARCHAR(50),
password VARCHAR(50),
CONSTRAINT agent_pkey PRIMARY KEY (id)
)
CREATE TABLE card(
id SERIAL,
card_no NUMERIC(8),
password VARCHAR(50),
agent_id NUMERIC(8),
CONSTRAINT card_pkey PRIMARY KEY (id)
)
只创建了主键。