我使用IntelliJ从数据库生成/映射表。
现在我想更新一个表的数据库,我想通过ORM(JPA)来完成。
我创建了实体类:
@Entity
@Table(name = "protocol", schema = "swprojekt")
public class ProtocolEntity {
private int protocolId;
private String name;
private Date expires;
private String description;
private DocumentEntity document;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "protocol_id", nullable = false)
public int getProtocolId() {
return protocolId;
}
public void setProtocolId(int protocolId) {
this.protocolId = protocolId;
}
@Basic
@Column(name = "name", nullable = false, length = 3000)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Basic
@Column(name = "expires", nullable = false)
public Date getExpires() {
return expires;
}
public void setExpires(Date expires) {
this.expires = expires;
}
@OneToOne(fetch=FetchType.LAZY)
@JoinColumn(name="document")
public DocumentEntity getDocument() {
return document;
}
public void setDocument(DocumentEntity document) {
this.document = document;
}
@Basic
@Column(name = "description", nullable = false, length = 3000)
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof ProtocolEntity)) return false;
ProtocolEntity that = (ProtocolEntity) o;
if (getProtocolId() != that.getProtocolId()) return false;
if (!getName().equals(that.getName())) return false;
if (!getExpires().equals(that.getExpires())) return false;
if (!getDescription().equals(that.getDescription())) return false;
return getDocument().equals(that.getDocument());
}
@Override
public int hashCode() {
int result = getProtocolId();
result = 31 * result + getName().hashCode();
result = 31 * result + getExpires().hashCode();
result = 31 * result + getDescription().hashCode();
result = 31 * result + getDocument().hashCode();
return result;
}
然而,现在我不确定。如何强制ORM创建表?只运行应用程序不起作用。我必须制作/设置什么配置?