对Java / Spring / Hibernate堆栈来说是新的。我无法使用apache poi从xlsx表中提取数据并保存到mssql数据库。使用内存数据库Derby,这一切都很好,这使我相信这与在java类和mssql数据库表之间映射的数据有关。
数据库:
CREATE TABLE BASICS.IncomingData.BulkRefundUpload (
id int PRIMARY KEY,
daxPaymentReference varchar(255),
amount float,
refundReason varchar(255),
invoiceId varchar(255),
processingStatus varchar(255),
retryCount int,
iglobisRequest varchar(255),
iglobisResponse varchar(255),
refundStatus varchar(255),
createDateTime date,
createdBy varchar(255),
updateDateTime date,
modifiedBy varchar(255)
)
班级:
// omitted imports
@Entity
@Table(name = "IncomingData.BulkRefundUpload")
public class Refund {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", updatable = false, nullable = false)
private int id;
@Column
private String daxPaymentReference;
@Column
private double amount;
@Column
private String refundReason;
@Column
private String invoiceId;
@Column
private String processingStatus;
@Column
private int retryCount;
@Column
private String iglobisRequest;
@Column
private String iglobisResponse;
@Column
private String refundStatus;
@Column
@CreationTimestamp
private Date createDateTime;
@Column
private String createdBy;
@Column
@UpdateTimestamp
private Date updateDateTime;
@Column
private String modifiedBy;
// no arg constructor
public Refund() {}
// regular constructor
public Refund(String daxPaymentReference, double amount, String refundReason, String invoiceId, String processingStatus, int retryCount, String iglobisRequest, String iglobisResponse, String refundStatus, String createdBy, String modifiedBy) {
super();
this.daxPaymentReference = daxPaymentReference;
this.amount = amount;
this.refundReason = refundReason;
this.invoiceId = invoiceId;
this.processingStatus = processingStatus;
this.retryCount = retryCount;
this.iglobisRequest = iglobisRequest;
this.iglobisResponse = iglobisResponse;
this.refundStatus = refundStatus;
this.createdBy = createdBy;
this.modifiedBy = modifiedBy;
}
// getters and setters omitted
}
然后尝试写入数据的方法将遍历xlsx中的行:
List<Refund> refunds = new ArrayList<>();
sheet.rowIterator().forEachRemaining(row -> {
if(row.getRowNum() != 0) {
refunds.add(new Refund(
row.getCell(0).getStringCellValue(), //daxPaymentReference
row.getCell(1).getNumericCellValue(), //amount
row.getCell(2).getStringCellValue(), //refundReason
"",
"new",
0,
"",
"",
"",
"defaultCreatedByUser",
""
));
}
});
最后是错误:
Hibernate: select next value for hibernate_sequence
2019-01-23 13:58:04.260 WARN 1544 --- [nio-8080-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 102, SQLState: S0001
2019-01-23 13:58:04.260 ERROR 1544 --- [nio-8080-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper : Incorrect syntax near 'hibernate_sequence'.
2019-01-23 13:58:04.315 ERROR 1544 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet] with root cause
com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near 'hibernate_sequence'.