我正在开发一个jpa项目。我的问题是,我的笔记本电脑忽略了@Column和@JoinColumn名称属性,但我的电脑没有。我不知道问题出在哪里...我已经清理并构建了项目(java maven项目,使用了eclipse链接2.5),但是他将id字段命名为数据库中的“ID”而不是“measureddata_id”。另一方面,在我的电脑上,他将id字段命名为“measureddata_id”(以其为工作)。
所以我假设,我的笔记本电脑忽略了我的实体中的@Column和@JoinColumn字段。
我笔记本电脑上的第二个是来自我的存储库的克隆,文件和依赖(依赖的版本号也是)完全相同。
以下是我的两个实体:
public class MeasuredDataEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "measureddata_id")
private Long id;
@Column(nullable = false, updatable = false)
@Temporal(javax.persistence.TemporalType.TIMESTAMP)
private Date createTime;
@JoinColumn(nullable = false)
@OneToOne
private WpsProcessEntity process;
@OneToMany(fetch = FetchType.EAGER, cascade = {CascadeType.ALL})
@JoinColumn(name = "owner_id", referencedColumnName = "measureddata_id")
private List<AbstractQosEntity> data;
public MeasuredDataEntity() {
this.data = new ArrayList<AbstractQosEntity>();
}
public MeasuredDataEntity(List<AbstractQosEntity> qosEntities) {
this.data = qosEntities;
this.createTime = new Date();
}
public boolean add(AbstractQosEntity e) {
return data.add(e);
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public WpsProcessEntity getProcess() {
return process;
}
public void setProcess(WpsProcessEntity process) {
this.process = process;
}
public List<AbstractQosEntity> getData() {
return data;
}
public void setData(List<AbstractQosEntity> data) {
this.data = data;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof MeasuredDataEntity)) {
return false;
}
MeasuredDataEntity other = (MeasuredDataEntity) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
for (AbstractQosEntity e : data) {
builder.append(e);
builder.append("\n");
}
return builder.toString();
}
}
第二个实体
@Entity
public abstract class AbstractQosEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Hide
@GeneratedValue(strategy = GenerationType.AUTO)
protected Long id;
/*
@Hide
@OneToOne
@JoinColumn(nullable = false)
private MeasuredDataEntity owner;*/
public abstract String getEntityName();
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof AbstractQosEntity)) {
return false;
}
AbstractQosEntity other = (AbstractQosEntity) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
return "data.entity.AbstractQosEntity[ id=" + id + " ]";
}
}
我很感谢你的帮助!
答案 0 :(得分:0)
你的笔记本电脑上的eclipse链接版本怎么样?