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

HiberateAnnotations如何配置嵌入式组件(embeddedcomponent)

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

1.我的表结构

createtablePERSONAL

(

IDNUMBERnotnull,

NAMEVARCHAR2(20),

HOME_STREETVARCHAR2(255),

HOME_CITYVARCHAR2(255),

HOME_PROVINCEVARCHAR2(255),

HOME_ZIPCODEVARCHAR2(255),

COM_STREETVARCHAR2(255),

COM_CITYVARCHAR2(255),

COM_PROVINCEVARCHAR2(255),

COM_ZIPCODEVARCHAR2(255)

)

altertablePERSONALaddconstraintPK_PERSONAL_ID_1primarykey(ID)

2.Personal.java

@SuppressWarnings("serial")

@Entity

@Table(name="Personal")

@SequenceGenerator(name="PERSONAL_SEQ",sequencename="PERSONAL_SEQ")

publicclassPersonalimplementsSerializable{

privateintid;

privateStringname;

@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"))

})

privateAddresshomeAddress;

@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"))

})

privateAddresscomAddress;

publicPersonal(){}

publicPersonal(Stringname,AddresshomeAddress,AddresscomAddress){

this.name=name;

this.homeAddress=homeAddress;

this.comAddress=comAddress;

}

publicAddressgetComAddress(){

returncomAddress;

}

publicvoidsetComAddress(AddresscomAddress){

this.comAddress=comAddress;

}

publicAddressgetHomeAddress(){

returnhomeAddress;

}

publicvoidsetHomeAddress(AddresshomeAddress){

this.homeAddress=homeAddress;

}

@Id

@GeneratedValue(generator="PERSONAL_SEQ")

publicintgetId(){

returnid;

}

@SuppressWarnings("unused")

privatevoidsetId(intid){

this.id=id;

}

publicStringgetName(){

returnname;

}

publicvoidsetName(Stringname){

this.name=name;

}

}

3.Address.java

@SuppressWarnings("serial")

@Embeddable

publicclassAddressimplementsSerializable{

privateStringstreet;

privateStringcity;

privateStringprovince;

privateStringzipcode;

publicAddress(){

//TODOAuto-generatedconstructorstub

}

publicAddress(Stringstreet,Stringcity,Stringprovince,Stringzipcode){

this.street=street;

this.city=city;

this.province=province;

this.zipcode=zipcode;

}

@Column(name="city",insertable=false,updatable=false)

publicStringgetCity(){

returncity;

}

publicvoidsetCity(Stringcity){

this.city=city;

}

@Column(name="province",insertable=false,updatable=false)

publicStringgetProvince(){

returnprovince;

}

publicvoidsetProvince(Stringprovince){

this.province=province;

}

@Column(name="street",insertable=false,updatable=false)

publicStringgetStreet(){

returnstreet;

}

publicvoidsetStreet(Stringstreet){

this.street=street;

}

@Column(name="zipcode",insertable=false,updatable=false)

publicStringgetZipcode(){

returnzipcode;

}

publicvoidsetZipcode(Stringzipcode){

this.zipcode=zipcode;

}

}

相关推荐