[英]Apache Ignite repository save method is doing only UPDATE instead of INSERT
我正在開發一個使用 Apache Ignite 作為緩存存儲的 Spring Boot + Impala 應用程序。 問題是IgniteRepository.save(key,entity)
只運行 UPDATE 查詢而不是 INSERT。
pom.xml
<ignite.version>2.14.0</ignite.version>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-spring-data-ext</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-core</artifactId>
<version>${ignite.version}</version>
</dependency>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-indexing</artifactId>
<version>${ignite.version}</version>
</dependency>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-spring</artifactId>
<version>${ignite.version}</version>
</dependency>
點燃配置:
IgniteConfiguration cfg = new IgniteConfiguration();
cfg.setIgniteInstanceName("springDataNode");
cfg.setPeerClassLoadingEnabled(true);
CacheConfiguration ccfg = new CacheConfiguration("XYZCache");
ccfg.setIndexedTypes(Long.class, XYZ.class);
ccfg.setCacheMode(CacheMode.PARTITIONED);
ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
ccfg.setReadThrough(true);
ccfg.setWriteThrough(true);
ccfg.setWriteBehindEnabled(true);
CacheJdbcPojoStoreFactory<Long, XYZ> factory = new CacheJdbcPojoStoreFactory<>();
factory.setDataSourceBean("ImpalaDataSource");
JdbcType jdbcType = new JdbcType();
jdbcType.setCacheName("XYZCache");
jdbcType.setKeyType(Long.class);
jdbcType.setValueType(XYZ.class);
jdbcType.setDatabaseTable("schema.table");
jdbcType.setKeyFields(new JdbcTypeField(Types.BIGINT, "id", Long.class, "id"));
jdbcType.setValueFields(
new JdbcTypeField(Types.VARCHAR, "comments", String.class, "comments"),
new JdbcTypeField(Types.BIGINT, "id", Long.class, "id")
);
factory.setTypes(jdbcType);
ccfg.setCacheStoreFactory(factory);
cfg.setCacheConfiguration(ccfg);
return IgniteSpring.start(cfg, applicationContext);
點燃存儲庫:
@RepositoryConfig(cacheName = "XYZCache")
public interface XYZRepository extends IgniteRepository<XYZ, Long> {
@Query("select * FROM XYZ WHERE comments=?")
List<XYZ> test(String comments);
@Query("insert into XYZ (id,comments) values (?,?)")
List<XYZ> customSave(Long id,String comments);
}
POJO:
@Data
public class XYZ implements Serializable {
private static final long serialVersionUID = -2677636393779376050L;
@QuerySqlField
private Long id;
@QuerySqlField
private String comments;
}
調用代碼:
xyzRepository.save(id, xyz);
xyzRepository.customSave(id, comments);
這兩種方法都通過運行UPDATE查詢(而不是INSERT )來拋出錯誤,這在 Impala 中不受支持,也不是我打算做的:
由以下原因引起:org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException:無法更新密鑰(如果可能重試更新)。:[1671548234688] 在 org.apache.ignite.internal.processors.cache.GridCacheUtils.convertToCacheException(GridCacheUtils .java:1251) ~[ignite-core-2.14.0.jar:2.14.0]
由以下原因引起:org.apache.ignite.IgniteCheckedException:數據庫中的更新條目失敗 [table=schema.table,entry=Entry [key=1671548234688,val=pkg.XYZ [idHash=1354181174,hash=991365654,id=1671548234688,評論=test]]] 在 org.apache.ignite.internal.processors.cache.store.GridCacheStoreManagerAdapter.put(GridCacheStoreManagerAdapter.java:593) 在 org.apache.ignite.internal.processors.cache.GridCacheMapEntry$AtomicCacheUpdateClosure.update(GridCacheMapEntry .java:6154) 在 org.apache.ignite.internal.processors.cache.GridCacheMapEntry$AtomicCacheUpdateClosure.call(GridCacheMapEntry.java:5918) 在 org.apache.ignite.internal.processors.cache.GridCacheMapEntry$AtomicCacheUpdateClosure.call(GridCacheMapEntry .java:5603) 在 org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree$Invoke.invokeClosure(BPlusTree.java:4254) 在 org.apache.ignite.internal.processors.cache.persistence.tree .BPlusTree$Invoke.access$5700(BPlusTree.java:4148) 在 org.apache.ignite.internal.processors.cache.per sistence.tree.BPlusTree.invokeDown(BPlusTree.java:2226) at org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree.invoke(BPlusTree.java:2116)... 146 common frames omitted 由: javax.cache.integration.CacheWriterException: 數據庫中的更新條目失敗 [table=schema.table, entry=Entry [key=1671548234688, val=pkg.XYZ [idHash=1354181174, hash=991365654, id=1671548234688, comments=test ]]] 在 org.apache.ignite.cache.store.jdbc.CacheAbstractJdbcStore.writeUpsert(CacheAbstractJdbcStore.java:978) 在 org.apache.ignite.cache.store.jdbc.CacheAbstractJdbcStore.write(CacheAbstractJdbcStore.java:1029) 在org.apache.ignite.internal.processors.cache.store.GridCacheStoreManagerAdapter.put(GridCacheStoreManagerAdapter.java:585)... 省略了153個常用框架
原因:com.cloudera.impala.support.exceptions.GeneralException:[Cloudera]ImpalaJDBCDriver 處理查詢/語句時出錯。 錯誤代碼:0,SQL 狀態:TStatus(statusCode:ERROR_STATUS, sqlState:HY000, errorMessage:AnalysisException: Impala 不支持修改非 Kudu 表:schema.table),查詢:UPDATE
schema
。table
設置table
。comments
= '測試' WHERE(table
。id =id
)。 ... 省略了 163 個公共框架
這里的問題是什么? 為什么 Apache Ignite 強制更新? 我怎樣才能改變這種行為?
我還實現了 Persistable 接口並覆蓋 isNew() 以返回 true 但它沒有用。
PS:選擇查詢工作正常(findAll、findById 等),包括自定義test()方法。 因此,不存在數據源配置問題,我能夠連接到 Impala。
這可能是因為您使用的方言沒有設置合並。
請參閱此處:了解流程。 這是根據您發布的堆棧跟蹤。
org.apache.ignite.cache.store.jdbc.CacheAbstractJdbcStore.writeUpsert(CacheAbstractJdbcStore.java:978) at <br>
org.apache.ignite.cache.store.jdbc.CacheAbstractJdbcStore.write(CacheAbstractJdbcStore.java:1029) at <br>
org.apache.ignite.internal.processors.cache.store.GridCacheStoreManagerAdapter.put(GridCacheStoreManagerAdapter.java:585) ..
或者,您可以編寫自己的數據存儲工廠。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.