我有简单的POJO:
@Entity
@Table(name = "t_address")
@SecondaryTables({
@SecondaryTable(name="t_city"),
@SecondaryTable(name="t_country")
})
public class Address{
@Id
@GeneratedValue
private Long id;
private String street1;
private String street2;
@Column(table="t_city")
private String city;
@Column(table="t_city")
private String state;
@Column(table="t_city")
private String zipcode;
@Column(table="t_country")
private String country;
// setter - getter
}
然后在我的Main课程中,我有一个像:
这样的实例Address address = new Address();
address.setStreet1("boulevard of broken dream");
address.setStreet2("abbey road");
address.setCity("San Fransisco");
address.setState("California");
address.setZipcode("13460");
address.setCountry("USA");
// some variable declaration
tx.begin();
em.persist(address);
tx.commit();
执行Main类后,我在数据库中有3个表:
查询每个表后,为什么数据只存储在t_city和t_country中,而不是存储在t_address中?你能解释一下原因吗?