已经给我一个脚本,该脚本可以从MySQL脚本生成一些实体,然后我在IntelliJ ide中自动生成了它。
我从脚本中创建了三个pojos
package com.mkl.data.entities;
public class Event {
private long id;
private long petId;
private String event;
private String remark;
private java.sql.Date date;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public long getPetId() {
return petId;
}
public void setPetId(long petId) {
this.petId = petId;
}
public String getEvent() {
return event;
}
public void setEvent(String event) {
this.event = event;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
public java.sql.Date getDate() {
return date;
}
public void setDate(java.sql.Date date) {
this.date = date;
}
}
现在的问题是,没有注释适合jpa。我会手动执行此操作,但是我的问题是主键未设置为典型关系,而只是常规的原始值。
所有者ID用作我宠物表中的前瞻密钥。
package com.mkl.data.entities;
import javax.persistence.*;
@Entity
public class Pet {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column
private String name;
private java.sql.Date birth;
private String species;
private java.sql.Date death;
//just regular variable
private long ownerId;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public java.sql.Date getBirth() {
return birth;
}
public void setBirth(java.sql.Date birth) {
this.birth = birth;
}
public String getSpecies() {
return species;
}
public void setSpecies(String species) {
this.species = species;
}
public java.sql.Date getDeath() {
return death;
}
public void setDeath(java.sql.Date death) {
this.death = death;
}
public long getOwnerId() {
return ownerId;
}
public void setOwnerId(long ownerId) {
this.ownerId = ownerId;
}
}
在数据库扩展列中,它显示了这种关系,但是我并没有真正出现在pojo中...
我应该改为将所有关系更改为JPA中的典型方式
@ManyToOne
private Owner owner;
还是我应该保留原谅的钥匙?也许带有注释,以刷新所有者表?