私は、テーブルに移動したい400万の生成されたエンティティのリストを持っています。私は入れませんがLocalDateTimeをnamedParameterJdbcTemplateで保存します。
public int[] bulkSaveInvoices(List<Invoice> invoices){
String insertSQL = "INSERT INTO invoices VALUES (:id, :exactIssueTime, :finalIssueTime, :issuer, :groupID)";
SqlParameterSource[] sqlParams = SqlParameterSourceUtils.createBatch(invoices.toArray());
int[] insertCounts = namedParameterJdbcTemplate.batchUpdate(insertSQL, sqlParams);
return insertCounts;
}
:私guesはこのようなNamedParameterJdbcTemplate.batchUpdate()
である - それは私が最適にそれをしたいエンティティの大きな数であるとして
@Data
@AllArgsConstructor
@Entity
@Table(name = "invoices")
public class Invoice {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
Long id;
@Column(name = "exact_iss_time")
private LocalDateTime exactIssueTime;
@Column(name = "final_iss_time")
private LocalDateTime finalIssueTime;
@Column(name = "issuer")
private String issuer;
@Column(name = "groupid")
private Integer groupID;
protected Invoice() {
}
}
:エンティティは、タイプLocalDateTime
でフィールドを持っていますエラー:
org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [INSERT INTO invoices VALUES (?, ?, ?, ?, ?)]; nested exception is org.postgresql.util.PSQLException: Can't infer the SQL type to use for an instance of java.time.LocalDateTime. Use setObject() with an explicit Types value to specify the type to use.
- 私はこの権利をやっている - この
LocalDateTime
私を修正するどのようにあればこの場合、ssue? - を挿入するのに最も最適な方法である方法よりも間違った方法であれば、400万のテストエンティティがSpringブートでテーブルに生成されますか? データベース?
を使用することができるため、コンバータを追加してみてください'LocalDateTime'をデータベースに挿入する前に' Timestamp'に設定してください。または、yuoがJPAを使用してバッチインサートを行い、 'hibernate0-java8'を使用すると仮定するか、またはあなたがHibernate 5.2上にいる場合は、それを挿入することができます。 –