java.lang.IllegalAccessError:MappingCassandraConverter在使用Spring Cassandra进行插入时出错

ryevplcw  于 2022-09-27  发布在  Java
关注(0)|答案(1)|浏览(135)

我是初来乍到的,所以请原谅我的基本问题。我正在使用基于spring的cassandra进行一些CRUD操作。一个简单的插入似乎不起作用,我想知道是否有人能指出我做错了什么。下面是我简单地插入时得到的错误

java.lang.IllegalAccessError: tried to access class org.springframework.data.mapping.model.BeanWrapper from class org.springframework.data.cassandra.convert.MappingCassandraConverter
at org.springframework.data.cassandra.convert.MappingCassandraConverter.writeInsertFromObject(MappingCassandraConverter.java:233) ~[spring-data-cassandra-1.2.2.RELEASE.jar:na]
at org.springframework.data.cassandra.convert.MappingCassandraConverter.write(MappingCassandraConverter.java:222) ~[spring-data-cassandra-1.2.2.RELEASE.jar:na]
at org.springframework.data.cassandra.core.CassandraTemplate.createInsertQuery(CassandraTemplate.java:841) ~[spring-data-cassandra-1.2.2.RELEASE.jar:na]
at org.springframework.data.cassandra.core.CassandraTemplate.doInsert(CassandraTemplate.java:640) ~[spring-data-cassandra-1.2.2.RELEASE.jar:na]
at org.springframework.data.cassandra.core.CassandraTemplate.insert(CassandraTemplate.java:238) ~[spring-data-cassandra-1.2.2.RELEASE.jar:na]
at org.springframework.data.cassandra.core.CassandraTemplate.insert(CassandraTemplate.java:233) ~[spring-data-cassandra-1.2.2.RELEASE.jar:na]

代码如下:

@Configuration
@PropertySource(value = { "classpath:cassandra.properties" })
@EnableCassandraRepositories
public class CassandraConfig {

    @Autowired
    private Environment environment;

    @Bean
    public CassandraOperations cassandraTemplate(Session someSession) throws Exception {
         return new CassandraTemplate(someSession);
    }

    @Bean
    public CassandraMappingContext mappingContext() {
        return new BasicCassandraMappingContext();
    }

    @Bean
    public CassandraConverter converter() {
        return new MappingCassandraConverter(mappingContext());
    }}

假设会话有效。下面是实际执行写入的代码

@Component
public class SomeQueries {
@Autowired
CassandraOperations cassandraOps;

public void insertCart(Addresses addr){
    cassandraOps.insert(addr);
}
}

这是地址的对象:

@Data
        @NoArgsConstructor
        @Table(value = "addresses")
        public class Addresses implements Serializable{

            @PrimaryKeyColumn(name = "account_id", ordinal = 0, type = PrimaryKeyType.PARTITIONED)
            private UUID accountId;

            @PrimaryKeyColumn(name = "address_id", ordinal = 1, type = PrimaryKeyType.PARTITIONED)
            private int addressId;

            @PrimaryKeyColumn(name = "is_primary", ordinal = 2, type = PrimaryKeyType.PARTITIONED)
            private boolean isPrimary;

            @Column("name") private String name;
            @Column("creation_date") private Date creationTimestamp;
            @Column("last_modified_date") private Date lastModifiedTimestamp;   

            @Override
            public int hashCode() {
                final int prime = 31;
                int result = 1;
                result = prime * result + ((accountId == null) ? 0 : accountId.hashCode());
                result = prime * result + addressId;
                result = prime * result + ((creationTimestamp == null) ? 0 : creationTimestamp.hashCode());
                result = prime * result + (isPrimary ? 1231 : 1237);
                result = prime * result + ((lastModifiedTimestamp == null) ? 0 : lastModifiedTimestamp.hashCode());
                result = prime * result + ((name == null) ? 0 : name.hashCode());
                return result;
            }

            @Override
            public boolean equals(Object obj) {
                if (this == obj)
                    return true;
                if (obj == null)
                    return false;
                if (getClass() != obj.getClass())
                    return false;
                DeliveryAddresses other = (DeliveryAddresses) obj;
                if (accountId == null) {
                    if (other.accountId != null)
                        return false;
                } else if (!accountId.equals(other.accountId))
                    return false;
else if (!address.equals(other.address))
                    return false;
                if (addressId != other.addressId)
                    return false;
                if (creationTimestamp == null) {
                    if (other.creationTimestamp != null)
                        return false;
                } else if (!creationTimestamp.equals(other.creationTimestamp))
                    return false;
                if (isPrimary != other.isPrimary)
                    return false;
                if (lastModifiedTimestamp == null) {
                    if (other.lastModifiedTimestamp != null)
                        return false;
                } else if (!lastModifiedTimestamp.equals(other.lastModifiedTimestamp))
                    return false;
                if (name == null) {
                    if (other.name != null)
                        return false;
                } else if (!name.equals(other.name))
                    return false;
                return true;
            }
            }

我是否缺少初始化的内容?

pjngdqdw

pjngdqdw1#

BeanWrapper在Spring Data Cassandra 1.2.0.版本中已弃用,并在代码中标记为删除TODO注解,在Github上MappingCassandraConverter BeanWrapper的最新代码中已删除。
您可以将Spring Data Cassandra升级到版本1.3.0,BeanDrapper异常将消失。

相关问题