테이블로 이동하려는 4 백만 개의 생성 된 엔터티 목록이 있습니다. 엔티티 유형 LocalDateTime
과 필드가 :namedParameterJdbcTemplate을 사용하여 LocalDateTime 저장
@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() {
}
}
그것이 내가 최적를 수행 할 기관의 큰 숫자이기 때문에 - 이런 NamedParameterJdbcTemplate.batchUpdate()
함께 I gues : 나는
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;
}
가 계속하지만이 오류 :이 권리를하고
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 만 개의 테스트 엔티티가 스프링 부트로 테이블에 생성됩니까? 데이터베이스?
를 사용하거나 변환 'LocalDateTime'을 데이터베이스에 삽입하기 전에 'Timestamp'에 저장하십시오. 또는 yuo가 hibernate를 사용하여 JPA를 사용하여 배치를 삽입하고'hibernate0-java8'을 사용하거나 당신이 Hibernate 5.2에 있다면 그냥 삽입 할 수 있다고 가정하십시오. –