私はEmbeddedableクラスAddressを持っています。アイデアは、@AttributeOverrideを使用して従来のデータベーススキーマにマッピングすることです。しかし、フィールドをオプションにしたい。たとえば、すべてのレコードにSTREET_ADDRESS_2があるわけではありません。Hibernate Embeddableクラスのオプションフィールド
以下のクラスは、データベースに永久保存されますが、getAll()操作を実行するときに "java.sql.SQLSyntaxErrorException:ユーザーが権限を持っていないか、オブジェクトが見つかりません"という爆発で爆発します。特に、getStreet2()メソッドは問題を引き起こします。組み込みクラスを使用する
@Embeddable
public class Address implements Serializable {
private static final long serialVersionUID = 1L;
private String street1;
private String street2;
private String state;
private String zip;
private String city;
private String phone;
@Column(name = "STREET1", updatable=false, insertable=false)
public String getStreet1() {
return street1;
}
public void setStreet1(String street1) {
this.street1 = street1;
}
//@Basic(optional=true)
@Column(name="STREET2", insertable=false, updatable=false)
@NotFound(action=NotFoundAction.IGNORE)
public String getStreet2() {
return street2;
}
public void setStreet2(String street2) {
this.street2 = street2;
}
@Column(name="STATE", updatable=false, insertable=false)
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
@Column(name="ZIP", updatable=false, insertable=false)
public String getZip() {
return zip;
}
public void setZip(String zip) {
this.zip = zip;
}
@Column(name="CITY", updatable=false, insertable=false)
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
@Column(name="PHONE", updatable=false, insertable=false)
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
@Override
public String toString() {
return "Address [street1=" + street1 + ", street2=" + street2
+ ", state=" + state + ", zip=" + zip + ", city=" + city
+ ", phone=" + phone + "]";
}
呼び出しは次のようになります。
@Embedded
@AttributeOverrides({
@AttributeOverride(name = "street1", column = @Column(name = "PERSON_STREET_1")),
@AttributeOverride(name = "street2", column = @Column(name = "PERSON_STREET_2")),
@AttributeOverride(name = "city", column = @Column(name = "PERSON_CITY")),
@AttributeOverride(name = "state", column = @Column(name = "PERSON_STATE")),
@AttributeOverride(name = "zip", column = @Column(name = "PERSON_ZIP")),
@AttributeOverride(name = "phone", column = @Column(name = "SOLDIER_PHONE")) })
@NotFound(action=NotFoundAction.IGNORE)
public Address getPersonAddress() {
return personAddress;
}
public void setPersonAddress(Address personAddress) {
this.personAddress = personAddress;
}
@Embedded
@AttributeOverrides({
@AttributeOverride(name = "street1", column = @Column(name = "DEPARTMENT_STREET")),
@AttributeOverride(name = "city", column = @Column(name = "DEPARTMENT_CITY")),
@AttributeOverride(name = "state", column = @Column(name = "DEPARTMENT_STATE")),
@AttributeOverride(name = "zip", column = @Column(name = "DEPARTMENT_ZIP")),
@AttributeOverride(name = "phone", column = @Column(name = "UNIT_PHONE")) })
public Address getDepartmentAddress() {
return DepartmentAddress;
}
public void setDepartmentAddress(Address DepartmentAddress) {
this.DepartmentAddress = DepartmentAddress;
}
部署アドレスがオーバーライドするデータベース内STREET2を持っていないため爆破するようです。
誰でも手助けできますか?