gpt4 book ai didi

spring-boot - 具有用户定义类型的 map 的 Sprint-data-Cassandra 映射失败,错误为 "not of type of the persistent entity"

转载 作者:行者123 更新时间:2023-12-04 18:28:37 25 4
gpt4 key购买 nike

这是我在 casssandra 中的用户定义类型:

  create type app
( app_id uuid,
app_name varchar,
maker varchar
);

我的表带有这种用户定义类型的 map
 create table device 
( device_id timeuuid,
apps map<uuid,frozen<app>>,

primary key (device_id)
);

它在 Java 中的映射
@Table("device")
public class Device {

@PrimaryKey
@Column("device_id")
private UUID device_id;


@Column("apps")
private Map<UUID, App> apps;

}


@UserDefinedType
public class App {

@Column("app_id")
private UUID app_id;

@Column("app_name")
private String app_name;

@Column("maker")
private String maker;

}

现在使用标准的 Sprind-data-cassandra CrudRepository:
public interface DeviceRepository extends CrudRepository<Device, UUID>{

当我尝试这样保存时
    Device st1 = new Device();
st1.setDevice_id(MyUtils.getRandomTimestampUUID());

/** Apps **/

App c1 = new App();
c1.setApp_id(MyUtils.getRandomTimestampUUID());
c1.setMaker("Maker of game 1");
c1.setApp_name("game 1");

App c2 = new App();
c2.setApp_id(MyUtils.getRandomTimestampUUID());
c2.setMaker("Maker of game 2");
c2.setApp_name("game 2");

Map<UUID, App> apps = new LinkedHashMap<UUID, App>();
apps.put(MyUtils.getRandomTimestampUUID(), c1);
apps.put(MyUtils.getRandomTimestampUUID(), c2);

st1.setApps(apps);

_deviceRepository.save(st1);

我得到这个异常(exception):
 java.lang.IllegalArgumentException: Target bean of type java.util.LinkedHashMap is not of type of the persistent entity (com.pfellwock.cassandra.type.App)!
at org.springframework.util.Assert.isTrue(Assert.java:68) ~[spring-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.data.mapping.model.BasicPersistentEntity.getPropertyAccessor(BasicPersistentEntity.java:397) ~[spring-data-commons-1.12.2.RELEASE.jar:na]
at org.springframework.data.cassandra.convert.MappingCassandraConverter.getConvertingAccessor(MappingCassandraConverter.java:608) ~[spring-data-cassandra-1.5.0.BUILD-SNAPSHOT.jar:na]
at org.springframework.data.cassandra.convert.MappingCassandraConverter.write(MappingCassandraConverter.java:322) ~[spring-data-cassandra-1.5.0.BUILD-SNAPSHOT.jar:na]
at org.springframework.data.cassandra.convert.MappingCassandraConverter.getWriteValue(MappingCassandraConverter.java:713) ~[spring-data-cassandra-1.5.0.BUILD-SNAPSHOT.jar:na]
at org.springframework.data.cassandra.convert.MappingCassandraConverter.getWriteValue(MappingCassandraConverter.java:665) ~[spring-data-cassandra-1.5.0.BUILD-SNAPSHOT.jar:na]
at org.springframework.data.cassandra.convert.MappingCassandraConverter.access$000(MappingCassandraConverter.java:86) ~[spring-data-cassandra-1.5.0.BUILD-SNAPSHOT.jar:na]
at org.springframework.data.cassandra.convert.MappingCassandraConverter$2.doWithPersistentProperty(MappingCassandraConverter.java:340) ~[spring-data-cassandra-1.5.0.BUILD-SNAPSHOT.jar:na]
at org.springframework.data.cassandra.convert.MappingCassandraConverter$2.doWithPersistentProperty(MappingCassandraConverter.java:335) ~[spring-data-cassandra-1.5.0.BUILD-SNAPSHOT.jar:na]
at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:312) ~[spring-data-commons-1.12.2.RELEASE.jar:na]
at org.springframework.data.cassandra.convert.MappingCassandraConverter.writeInsertFromWrapper(MappingCassandraConverter.java:335) ~[spring-data-cassandra-1.5.0.BUILD-SNAPSHOT.jar:na]
at org.springframework.data.cassandra.convert.MappingCassandraConverter.writeInsertFromObject(MappingCassandraConverter.java:329) ~[spring-data-cassandra-1.5.0.BUILD-SNAPSHOT.jar:na]
at org.springframework.data.cassandra.convert.MappingCassandraConverter.write(MappingCassandraConverter.java:314) ~[spring-data-cassandra-1.5.0.BUILD-SNAPSHOT.jar:na]
at org.springframework.data.cassandra.convert.MappingCassandraConverter.write(MappingCassandraConverter.java:298) ~[spring-data-cassandra-1.5.0.BUILD-SNAPSHOT.jar:na]
at org.springframework.data.cassandra.core.CassandraTemplate.createInsertQuery(CassandraTemplate.java:948) ~[spring-data-cassandra-1.5.0.BUILD-SNAPSHOT.jar:na]
at org.springframework.data.cassandra.core.CassandraTemplate.createInsertQuery(CassandraTemplate.java:717) ~[spring-data-cassandra-1.5.0.BUILD-SNAPSHOT.jar:na]
at org.springframework.data.cassandra.core.CassandraTemplate.doInsert(CassandraTemplate.java:708) ~[spring-data-cassandra-1.5.0.BUILD-SNAPSHOT.jar:na]
at org.springframework.data.cassandra.core.CassandraTemplate.insert(CassandraTemplate.java:290) ~[spring-data-cassandra-1.5.0.BUILD-SNAPSHOT.jar:na]
at org.springframework.data.cassandra.core.CassandraTemplate.insert(CassandraTemplate.java:285) ~[spring-data-cassandra-1.5.0.BUILD-SNAPSHOT.jar:na]

这是我在 gradle 中的设置:
compile("com.datastax.cassandra:cassandra-driver-core:3.1.1")
compile('org.springframework.boot:spring-boot-starter-data-cassandra')
compile("org.springframework.data:spring-data-cassandra:1.5.0.BUILD-SNAPSHOT")
compile("org.springframework.data:spring-cql:1.5.0.BUILD-SNAPSHOT")

最佳答案

当前 Spring 数据不支持自定义数据类型作为 map “应用程序”中的值。
即使您纠正了此错误,您也会在实体 [Device] 中为 [interface java.util.Map] 类型的属性 [app] 的集合内偶然发现其他类似的仅原始类型。

就这一点而言,错误将通过“@CassandraType(type = Name.MAP, userTypeName = "address",typeArguments={Name.TEXT,Name.CUSTOM})”消失

在类设备中的应用程序属性上。
NOTE* typeArguments 在 map 仅支持原始类型的情况下,假设添加了 CUSTOM。

关于spring-boot - 具有用户定义类型的 map 的 Sprint-data-Cassandra 映射失败,错误为 "not of type of the persistent entity",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41027241/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com