Hiberate Annotations如何配置嵌入式组件(embedded component)

Hiberate Annotations如何配置嵌入式组件(embedded component)


我想用Hiberate Annotations 配置嵌入式组,但怎么改也不对,报异常,望大哥们帮小弟看一下.指点指点.谢谢了.

1.我的表结构
create table PERSONAL
(
  ID NUMBER not null,
  NAME VARCHAR2(20),
  HOME_STREET VARCHAR2(255),
  HOME_CITY VARCHAR2(255),
  HOME_PROVINCE VARCHAR2(255),
  HOME_ZIPCODE VARCHAR2(255),
  COM_STREET VARCHAR2(255),
  COM_CITY VARCHAR2(255),
  COM_PROVINCE VARCHAR2(255),
  COM_ZIPCODE VARCHAR2(255)
)

alter table PERSONAL add constraint PK_PERSONAL_ID_1 primary key (ID)


2.Personal.java
@SuppressWarnings("serial")
@Entity
@Table(name = "Personal")
@SequenceGenerator(name = "PERSONAL_SEQ", sequenceName = "PERSONAL_SEQ")
public class Personal implements Serializable {
private int id;
private String name;

@Embedded
@AttributeOverrides({
@AttributeOverride(name="street",column=@Column(name="home_street")),
@AttributeOverride(name="city",column=@Column(name="home_city")),
@AttributeOverride(name="province",column=@Column(name="home_province")),
@AttributeOverride(name="zipcode",column=@Column(name="home_zipcode"))
})
private Address homeAddress;

@Embedded
@AttributeOverrides({
@AttributeOverride(name="street",column=@Column(name="com_street")),
@AttributeOverride(name="city",column=@Column(name="com_city")),
@AttributeOverride(name="province",column=@Column(name="com_province")),
@AttributeOverride(name="zipcode",column=@Column(name="com_zipcode"))
})
private Address comAddress;

public Personal(){}

public Personal(String name,Address homeAddress,Address comAddress){
this.name = name;
this.homeAddress = homeAddress;
this.comAddress = comAddress;
}

public Address getComAddress() {
return comAddress;
}

public void setComAddress(Address comAddress) {
this.comAddress = comAddress;
}

public Address getHomeAddress() {
return homeAddress;
}

public void setHomeAddress(Address homeAddress) {
this.homeAddress = homeAddress;
}

@Id
@GeneratedValue(generator="PERSONAL_SEQ")
public int getId() {
return id;
}

@SuppressWarnings("unused")
private void setId(int id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}


3.Address.java
@SuppressWarnings("serial")
@Embeddable
public class Address implements Serializable {
private String street;
private String city;
private String province;
private String zipcode;

public Address() {
  // TODO Auto-generated constructor stub
}

public Address(String street,String city,String province,String zipcode){
  this.street = street;
  this.city = city;
  this.province = province;
  this.zipcode = zipcode;
}

@Column(name="city",insertable=false, updatable=false)
public String getCity() {
  return city;
}
public void setCity(String city) {
  this.city = city;
}

@Column(name="province",insertable=false, updatable=false)
public String getProvince() {
  return province;
}
public void setProvince(String province) {
  this.province = province;
}
@Column(name="street",insertable=false, updatable=false)
public String getStreet() {
  return street;
}
public void setStreet(String street) {
  this.street = street;
}
@Column(name="zipcode",insertable=false, updatable=false)
public String getZipcode() {
  return zipcode;
}
public void setZipcode(String zipcode) {
  this.zipcode = zipcode;
}
}

你可能感兴趣的:(Hiberate Annotations如何配置嵌入式组件(embedded component))