我在尝试在Oracle中插入数据时遇到错误。
rg.springframework.web.util.NestedServletException:请求处理 失败;嵌套异常是 org.springframework.jdbc.UncategorizedSQLException:Hibernate 潮红:无法插入:[RallyDefect];未分类的SQLException for SQL [插入EDS_OPS_RALLY_DEFECTS_DUPLI(LAST_UPDATE_DATE, CLOSED_DATE,CREATION_DATE,DEFECT_ID,DEFECT_NAME,DESCRIPTION, 环境,ITERATION,NOTES,PRIORITY,PROJECT,RELEASE_NAME, 分辨率,严重性,状态,SUBMITTED_BY,SERIALNO)值(?,?,?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?)]; SQL状态[72000];错误 代码[1461]; ORA-01461:只能插入一个LONG值才能插入到 龙柱;嵌套异常是java.sql.BatchUpdateException: ORA-01461:只能插入一个LONG值才能插入LONG列
无法在各种帖子中看到解决方案。
DAO课程
public void addRallyDefects(RallyDefect rallyDefect) {
System.out.println("==inside RallyDaoImpl ==");
System.out.println("==rallyDefect =="+ rallyDefect.getDefectid());
sessionFactory.getCurrentSession().saveOrUpdate(rallyDefect);
//sessionFactory.getCurrentSession().flush();
}
服务实施
String[] defectattributes = { "FormattedID", "Name", "State",
"Description", "Severity", "Environment", "CreationDate",
"ClosedDate", "Resolution", "Notes", "Priority",
"LastUpdateDate", "Release", "Project", "SubmittedBy",
"Iteration", "Tag" };
try {
QueryRequest defects = new QueryRequest("defect");
defects.setFetch(new Fetch(defectattributes));
defects.setOrder("FormattedID ASC");
defects.setPageSize(1);
defects.setLimit(1000);
QueryResponse queryResponse = restApi.query(defects);
if (queryResponse.wasSuccessful()) {
JsonObject defect = new JsonObject();
for (JsonElement result : queryResponse.getResults()) {
defect = result.getAsJsonObject();
RallyDefect defectrows = new RallyDefect();
defectrows.setDefectid((defect.get("FormattedID")
.getAsString()));
defectrows.setDefectname((defect.get("Name").getAsString()));
defectrows.setStatus((defect.get("State").getAsString()));
if (defect.get("Description").isJsonNull()) {
defectrows.setDescription("");
} else {
defectrows.setDescription(html2text((defect.get("Description")
.getAsString())));
}
if(defect.get("Severity").isJsonNull()){
defectrows.setSeverity("");
}else{
defectrows.setSeverity((defect.get("Severity").getAsString()));
}
if(defect.get("Environment").isJsonNull()){
defectrows.setEnvironment("");
}else{
defectrows.setEnvironment((defect.get("Environment").getAsString()));
}
if(defect.get("CreationDate").isJsonNull()){
defectrows.setCreationDate((java.sql.Date)new Date());
}else{
defectrows.setCreationDate(convertDate((defect.get("CreationDate").getAsString())));
}
if(defect.get("ClosedDate").isJsonNull()){
defectrows.setClosedDate(new java.sql.Date(0));
}else{
defectrows.setClosedDate(convertDate((defect.get("ClosedDate").getAsString())));
}
if(defect.get("Resolution").isJsonNull()){
defectrows.setRelease("");
}else{
defectrows.setRelease(html2text((defect.get("Resolution").getAsString())));
}
if(defect.get("Notes").isJsonNull()){
defectrows.setNotes("");
}else{
defectrows.setNotes((defect.get("Notes").getAsString()));
}
if(defect.get("Priority").isJsonNull()){
defectrows.setPriority("");
}else{
defectrows.setPriority((defect.get("Priority").getAsString()));
}
if(defect.get("LastUpdateDate").isJsonNull()){
defectrows.setLastUpdateDate((java.sql.Date)new Date());
}else{
defectrows.setLastUpdateDate(convertDate((defect.get("LastUpdateDate").getAsString())));
}
if (defect.has("Release") && defect.get("Release").isJsonNull()) {
defectrows.setRelease("");
} else {
defectrows.setRelease((defect.get("Release").getAsJsonObject().get("Name").getAsString()));
}
if (defect.has("Project") && defect.get("Project").isJsonNull()) {
defectrows.setProject("");
} else {
defectrows.setProject((defect.get("Project").getAsJsonObject().get("Name").getAsString()));
}
if (defect.has("SubmittedBy") && defect.get("SubmittedBy").isJsonNull()) {
defectrows.setSubmittedBy("");
} else {
defectrows.setSubmittedBy((defect.get("SubmittedBy").getAsJsonObject().get("_refObjectName").getAsString()));
}
if (defect.has("Iteration") && defect.get("Iteration").isJsonNull()) {
defectrows.setIteration("");
} else {
defectrows.setIteration((defect.get("Iteration").getAsJsonObject().get("Name").getAsString()));
}
// adding Defects data
rallyDao.addRallyDefects(defectrows);
System.out.println("==Before exiting from Serivce == ");
}
} else {
System.err.println("The following errors occurred: ");
for (String err : queryResponse.getErrors()) {
System.err.println("\t" + err);
}
}
}
finally {
// Release all resources
restApi.close();
}
}
public static String html2text(String html){
return Jsoup.parse(html).text();
}
public static String replaceNull(String input) {
return input == null ? "" : input;
}
public static java.sql.Date convertDate(String datevalue) throws ParseException{
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
Date date1 = simpleDateFormat.parse(datevalue);
java.sql.Date sqlDate = new java.sql.Date(date1.getTime());
return sqlDate;
} }
一个重要的注意事项:我试图插入大约300条记录。这不是问题。
以下是我的Model类
@Entity
@Table(name="RALLY_DEFECTS")
public class RallyDefect implements Serializable{
private static final long serialVersionUID = -9L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "SERIALNO")
private Integer defectCountNum;
@Column(name = "DEFECT_ID")
private String defectid;
@Column(name="DEFECT_NAME")
private String defectname;
@Column(name = "STATUS")
private String status;
@Column(name = "DESCRIPTION")
private String description;
@Column(name = "SEVERITY")
private String severity;
@Column(name = "ENVIRONMENT")
private String environment;
@Column(name = "CREATION_DATE")
private Date creationDate;
@Column(name = "CLOSED_DATE")
private Date closedDate;
@Column(name = "RESOLUTION")
private String resolution;
@Column(name = "NOTES")
private String notes;
@Column(name = "PRIORITY")
private String priority;
@Column(name = "LAST_UPDATE_DATE")
private Date LastUpdateDate;
@Column(name = "RELEASE_NAME")
private String release;
@Column(name = "PROJECT")
private String project;
@Column(name = "SUBMITTED_BY")
private String submittedBy;
@Column(name = "ITERATION")
private String iteration;
}
表格定义
创建表RALLY_DEFECTS ( PROJECT VARCHAR2(3000 BYTE), DEFECT_ID VARCHAR2(1000 BYTE), DEFECT_NAME VARCHAR2(3000 BYTE), VARCHAR2(3900 BYTE), PRIORITY VARCHAR2(1000 BYTE), SEVERITY VARCHAR2(1000 BYTE), STATUS VARCHAR2(1000 BYTE), ENVIRONMENT VARCHAR2(1000 BYTE), SUBMITTED_BY VARCHAR2(1000 BYTE), OWNER VARCHAR2(1000 BYTE), TAGS VARCHAR2(3000 BYTE), RELEASE_NAME VARCHAR2(1000 BYTE), ITERATION VARCHAR2(1000 BYTE), CREATION_DATE DATE, 截止日期, LAST_UPDATE_DATE DATE, RESOLUTION VARCHAR2(3900 BYTE), NOTES VARCHAR2(3900 BYTE), SERIALNO NUMBER, 最后一天, 截止日期, 创建日期, RELEASE VARCHAR2(255 CHAR), SUBMITTEDBY VARCHAR2(255 CHAR) ) TABLESPACE OPS_DAT RESULT_CACHE(模式默认值) PCTUSED 0 PCTFREE 10 INITRANS 1 MAXTRANS 255 存储( 初始64K NEXT 1M MAXSIZE UNLIMITED MINEXTENTS 1 MAXEXTENTS无限 PCTINCREASE 0 BUFFER_POOL默认 FLASH_CACHE DEFAULT CELL_FLASH_CACHE默认 ) 测井 NOCOMPRESS NOCACHE NOPARALLEL 监控;