我与以下配置有一对一的关系:
@Entity
@Table(name = "org")
@SequenceGenerator(name = "default_gen", sequenceName = "haj_rasoul", allocationSize = 1)
public class Organization extends BaseEntity<Long> {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
和这堂课:
@Entity
@Table(name = "product")
@GenericGenerator(name = "default_gen", strategy = "foreign", parameters = @Parameter(name = "property", value = "reza"))
public class Product extends BaseEntity<Long> {
@Column(name = "DD")
private String description;
@Column(name = "PP")
private BigDecimal price;
@Column(name = "MM")
private String imageUrl;
@OneToOne
@PrimaryKeyJoinColumn(referencedColumnName = "id")
private Organization reza;
public Organization getReza() {
return reza;
}
public void setReza(Organization reza) {
this.reza = reza;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
public String getImageUrl() {
return imageUrl;
}
public void setImageUrl(String imageUrl) {
this.imageUrl = imageUrl;
}
}
和BaseEntity:
@MappedSuperclass
public abstract class BaseEntity<T> implements Serializable {
private static final long serialVersionUID = 4295229462159851306L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "default_gen")
private T id;
@Column(name = "updatedby")
private Date updatedDate;
public Date getUpdatedDate() {
return updatedDate;
}
public void setUpdatedDate(Date updatedDate) {
this.updatedDate = updatedDate;
}
public T getId() {
return id;
}
public void setId(T id) {
this.id = id;
}
}
当应用程序以更新模式启动以创建模型时,
它们已成功创建,但Organization
中不存在外键Product
,另一方面,如果组织的记录在作为外键的产品中,则可以删除组织记录。
哪里错了?
我该如何解决这个问题?