JPA @SecondaryTables,为什么我的主表是空的?虽然辅助表不是空的?

时间:2011-06-08 16:28:55

标签: java orm jpa java-ee jpa-2.0

我有简单的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_address [ID,STREET1,STREET2]
  • t_city [ID,CITY,STATE,ZIPCODE]
  • t_country [ID,COUNTRY]

查询每个表后,为什么数据只存储在t_city和t_country中,而不是存储在t_address中?你能解释一下原因吗?

0 个答案:

没有答案