我使用的是JPA、Spring、Extjs4MVC和mysql5.0服务器
我面临的一个问题是,我无法使用Hibernate + JPA将数据插入数据库。我使用JSON将数据发送到服务器端,然后这个对象与数据库交互并将json对象插入到数据库中。
我将json数据发送给
"Id": null,
"Name": "New task",
"StartDate": "2010-02-13T05:30:00",
"EndDate": "2010-02-13T05:30:00",
"Duration": 0,
"DurationUnit": "d",
"PercentDone": 0,
"ManuallyScheduled": false,
"Priority": 1,
"parentId": 22,
"index": 2,
"depth": 2,
"checked": null
我的Hibernate POJO是
private int id;
private Date startDate;
private Date endDate;
private int percentDone;
private String name;
private int priority;
private double duration;
private String durationUnit;
private int index;
private int depth;
private int parentId;
/**
* @return the id
*/
@Id
@GeneratedValue
@Column(name = "TASK_Id")
public int getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(int Id) {
this.id = Id;
}
/**
* @return the startDate
*/
@Temporal(TemporalType.DATE)
@Column(name = "TASK_Start_Date")
public Date getStartDate() {
return startDate;
}
/**
* @param startDate the startDate to set
*/
public void setStartDate(Date StartDate) {
this.startDate = StartDate;
}
/**
* @return the endDate
*/
@Temporal(TemporalType.DATE)
@Column(name = "TASK_End_Date")
public Date getEndDate() {
return endDate;
}
/**
* @param endDate the endDate to set
*/
public void setEndDate(Date EndDate) {
this.endDate = EndDate;
}
/**
* @return the percentDone
*/
@Column(name = "TASK_Percent_Done")
public int getPercentDone() {
return percentDone;
}
/**
* @param percentDone the percentDone to set
*/
public void setPercentDone(int PercentDone) {
this.percentDone = PercentDone;
}
/**
* @return the name
*/
@Column(name = "TASK_Name")
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String Name) {
this.name = Name;
}
/**
* @return the priority
*/
@Column(name = "TASK_Priority")
public int getPriority() {
return priority;
}
/**
* @param priority the priority to set
*/
public void setPriority(int Priority) {
this.priority = Priority;
}
/**
* @return the duration
*/
@Column(name = "TASK_Duration")
public double getDuration() {
return duration;
}
/**
* @param duration the duration to set
*/
public void setDuration(double Duration) {
this.duration = Duration;
}
/**
* @return the durationUnit
*/
@Column(name = "TASK_DurationUnit")
public String getDurationUnit() {
return durationUnit;
}
/**
* @param durationUnit the durationUnit to set
*/
public void setDurationUnit(String DurationUnit) {
this.durationUnit = DurationUnit;
}
/**
* @return the index
*/
@Column(name = "TASK_Index")
public int getIndex() {
return index;
}
/**
* @param index the index to set
*/
public void setIndex(int index) {
this.index = index;
}
/**
* @return the depth
*/
@Column(name = "TASK_Depth")
public int getDepth() {
return depth;
}
/**
* @param depth the depth to set
*/
public void setDepth(int depth) {
this.depth = depth;
}
/**
* @return the parentId
*/
@Column(name = "TASK_ParentId")
public int getParentId() {
return parentId;
}
/**
* @param parentId the parentId to set
*/
public void setParentId(int parentId) {
this.parentId = parentId;
}
当我传递上述JSON数据时,没有任何东西被插入到我的数据库中。我的hibernate查询触发如下
`Hibernate: insert into TASK(TASK_Depth, TASK_Duration, TASK_DurationUnit, TASK_End_Date, TASK_Index, TASK_Name, TASK_ParentId, TASK_Percent_Done, TASK_Priority, TASK_Start_Date)
values( ? , ?, ?, ?, ?, ?, ?, ?, ?, ?)`
没有任何东西被插入到我的数据库。当我的类id自动递增时,记录将被创建为空名称、startDate、endDate、parentId
所以我的问题是我做错了什么。我的hibernate Pojo映射有什么问题吗?如果是,那么任何解决这个问题的人都可以回复我的线程。
发布于 2012-01-02 06:38:51
我建议你把你的问题分成几个方面。
我记得我使用了一个Direct (杜尔)项目将数据从ExtJS发送到基于ExtJS的服务器(数据以JSON格式发送),所以我不能详细说明您的转换方法。
希望这能有所帮助
https://stackoverflow.com/questions/8697921
复制相似问题