2017-04-04 86 views
1

我有以下方法:錯誤進行隔離工作激起試圖挽救了Iterable

List<BinValue> binValues = Arrays 
     .stream(data) 
... 
     .collect(Collectors.toList()); 

     binValueRepo.deleteByStatId(databaseGlobals.getMarriedStat().getId()); 
//  for(BinValue binValue : binValues) { 
//   binValueRepo.save(binValue); 
//  } 
     binValueRepo.save(binValues); 

首先它準備BinValue實體的列表,然後嘗試將其保存到存儲庫。

的問題是:如果我試圖拯救整個列表,會出現以下錯誤:

org.springframework.dao.CannotAcquireLockException: error performing isolated work; SQL [n/a];... 

LockAcquisitionException: error performing isolated work 

org.sqlite.SQLiteException: [SQLITE_BUSY] The database file is locked (database is locked) 

如果我這樣做一,隨後一切正常(但慢)。

爲了填補BinValue我使用下面的代碼:

 BinValue ans = new BinValue(); 
     ans.setBin(bin); 
     ans.setRegion(region); 
     ... 

即我不填充主鍵字段。

它是這樣定義的:

@Entity 
@Table(name = "bin_values") 
@NoArgsConstructor 
@AllArgsConstructor 
public class BinValue { 

    @Id 
    @Column(name="id") 
    @GeneratedValue(generator="sqlite") 
    @TableGenerator(name="sqlite", table="sqlite_sequence", 
     pkColumnName="name", valueColumnName="seq", 
     pkColumnValue="bin_values") 
    @Getter 
    @Setter 
    private long id; 

回答

0

顯然,設置最大連接數爲1解決這個問題

@Bean 
    public DataSource dataSource() { 
     BasicDataSource ans = new BasicDataSource(); 
     ans.setDriverClassName("org.sqlite.JDBC"); 
     ans.setUrl("jdbc:sqlite:" + sqliteDatabaseFile().getAbsolutePath()); 
     ans.setMaxTotal(1); 


     return ans; 
    } 
相關問題