when i try to save a entity , it said:
Code:
QueryEntry qe = new QueryEntry();
qe.setTitle("test");
queryEntryDAO.save(qe);
org.springframework.dao.DataIntegrityViolationException: could not insert
when i try to insert a record in database like this:
insert into query_info (title) values ('test');
ok, when I load it , it said:
Can not set int field com.osssoft.query.entity.QueryEntry.parentId to null value
i think I have already set it's nullable is true,
any body can help me ?
this is my code , this question burder me server days
Code:
package com.osssoft.query.entity;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
/**
* 查询入口,记录查询语句与与层次树状关系
*
* @author lvjian
*
*/
@Entity
@Table(name = "query_entry")
public class QueryEntry implements Serializable {
private static final long serialVersionUID = -7413534140036087322L;
@Id
@GeneratedValue
private int id;
@Column(name = "title", length = 100)
private String title;
@Column(name = "parent_id")
private int parentId;
@ManyToOne
@JoinColumn(name = "parent_id", insertable = false, updatable = false, nullable = true)
private QueryEntry parent;
@OneToMany(mappedBy = "parent")
private Set<QueryEntry> children = new HashSet<QueryEntry>();
@Column(name = "prepare_sql", length = 2000)
private String prepareSql;
@Column(name = "query_sql", length = 2000)
private String querySql;
@Column(name = "clean_sql", length = 1000)
private String cleanSql;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public int getParentId() {
return parentId;
}
public void setParentId(int parentId) {
this.parentId = parentId;
}
public QueryEntry getParent() {
return parent;
}
public void setParent(QueryEntry parent) {
this.parent = parent;
}
public Set<QueryEntry> getChildren() {
return children;
}
public void setChildren(Set<QueryEntry> children) {
this.children = children;
}
public String getPrepareSql() {
return prepareSql;
}
public void setPrepareSql(String prepareSql) {
this.prepareSql = prepareSql;
}
public String getSql() {
return querySql;
}
public void setSql(String querySql) {
this.querySql = querySql;
}
public String getCleanSql() {
return cleanSql;
}
public void setCleanSql(String cleanSql) {
this.cleanSql = cleanSql;
}
}
[/code]