Я получаю NPE, выброшенный преобразователями cassandra, когда пытаюсь вставить объект в базу данных. JSON-представление POJO отображается в журналах. В коде оно снабжено полями @Table, @PrimaryKey и @Column. . Не уверен, влияет ли это на него, но POJO имеет один определяемый пользователем тип, который я соответствующим образом аннотировал как @CassandraType(type = CassandraType.Name.UDT, userTypeName = объявление). POJO для этого (поле объявления) также отмечается тегами @UserDefinedType(announcement).
Следуя примерам здесь Я настроил сеанс cassandra со следующим кодом
public void initialize() {
session = CqlSession.builder().addContactPoint(new InetSocketAddress(cassandraHost, cassandraPort))
.withAuthCredentials(csUsername, csPassword)
.withKeyspace(keyspace)
.withLocalDatacenter("datacenter1")
.build() ;
template = new CassandraTemplate(session);
logger.info("Cassandra client connection created");
}
public MetaDatatype saveMeta(MetaDatatype metaDatatype) {
logger.info("Adding new {} row for id: {}" , metaDatatype.getReferenceType().name(), metaDatatype.getReferenceId());
logger.info(new Gson().toJson(metaDatatype, MetaDatatype.class) );
return template.insert(metaDatatype);
}
Но после запуска кода вставки вот что я получаю
2020-09-29T09:40:34.683 INFO [http-nio-7891-exec-1] MetaRepository:21 - Adding metadatatype for ENTITY with id: ENTITY_d02f614f-2856-417e-a130-4a2aecd4817f
2020-09-29T09:40:34.684 INFO [http-nio-7891-exec-1] PersistenceClient:80 - Adding new ENTITY row for id: d02f614f-2856-417e-a130-4a2aecd4817f
2020-09-29T09:40:34.710 INFO [http-nio-7891-exec-1] PersistenceClient:81 - {"id":"ENTITY_d02f614f-2856-417e-a130-4a2aecd4817f","payments":["MOBILE_MONEY","CASH"],"priceRating":0,"announcement":{"timestamp":0,"message":"Shut for COVID-19"},"highlights":["LOCALLY_OWNED"],"deliveries":["VIRTUAL"],"wifiAvailable":true,"audiences":["KIDS"],"referenceType":"ENTITY","referenceId":"d02f614f-2856-417e-a130-4a2aecd4817f","addedTimestamp":1601386834683,"modifiedTimestamp":0,"metatype":"EATERY","appointment":true,"seating":["INDOOR"],"accesses":["WHEELCHAIR"],"parking":["STREET"],"amenities":["Dishwasher"],"facilities":["POOL"]}
2020-09-29T09:40:34.759 ERROR [http-nio-7891-exec-1] MetadataExchange:183 - Error occcured when adding metadata
java.lang.NullPointerException: null
at org.springframework.data.cassandra.core.convert.MappingCassandraConverter.lambda$new$1(MappingCassandraConverter.java:142) ~[spring-data-cassandra-3.0.4.RELEASE.jar!/:3.0.4.RELEASE]
at org.springframework.data.cassandra.core.convert.DefaultColumnTypeResolver.getUserType(DefaultColumnTypeResolver.java:470) ~[spring-data-cassandra-3.0.4.RELEASE.jar!/:3.0.4.RELEASE]
at org.springframework.data.cassandra.core.convert.DefaultColumnTypeResolver.resolve(DefaultColumnTypeResolver.java:260) ~[spring-data-cassandra-3.0.4.RELEASE.jar!/:3.0.4.RELEASE]
at org.springframework.data.cassandra.core.convert.DefaultColumnTypeResolver.resolve(DefaultColumnTypeResolver.java:127) ~[spring-data-cassandra-3.0.4.RELEASE.jar!/:3.0.4.RELEASE]
at org.springframework.data.cassandra.core.convert.MappingCassandraConverter.getWriteValue(MappingCassandraConverter.java:743) ~[spring-data-cassandra-3.0.4.RELEASE.jar!/:3.0.4.RELEASE]
at org.springframework.data.cassandra.core.convert.MappingCassandraConverter.writeMapFromWrapper(MappingCassandraConverter.java:491) ~[spring-data-cassandra-3.0.4.RELEASE.jar!/:3.0.4.RELEASE]
at org.springframework.data.cassandra.core.convert.MappingCassandraConverter.write(MappingCassandraConverter.java:457) ~[spring-data-cassandra-3.0.4.RELEASE.jar!/:3.0.4.RELEASE]
at org.springframework.data.cassandra.core.StatementFactory.insert(StatementFactory.java:307) ~[spring-data-cassandra-3.0.4.RELEASE.jar!/:3.0.4.RELEASE]
at org.springframework.data.cassandra.core.CassandraTemplate.doInsert(CassandraTemplate.java:639) ~[spring-data-cassandra-3.0.4.RELEASE.jar!/:3.0.4.RELEASE]
at org.springframework.data.cassandra.core.CassandraTemplate.insert(CassandraTemplate.java:629) ~[spring-data-cassandra-3.0.4.RELEASE.jar!/:3.0.4.RELEASE]
at org.springframework.data.cassandra.core.CassandraTemplate.insert(CassandraTemplate.java:617) ~[spring-data-cassandra-3.0.4.RELEASE.jar!/:3.0.4.RELEASE]
at com.ghyrate.dataservice.clients.PersistenceClient.saveMeta(PersistenceClient.java:82) ~[classes!/:1.0-SNAPSHOT]
at com.ghyrate.dataservice.repository.MetaRepository.addMeta(MetaRepository.java:22) ~[classes!/:1.0-SNAPSHOT]
at com.ghyrate.dataservice.processor.MetadataExchange.postMetadata(MetadataExchange.java:179) [classes!/:1.0-SNAPSHOT]
at com.ghyrate.dataservice.controllers.MetaDataController.postEntity(MetaDataController.java:56) [classes!/:1.0-SNAPSHOT]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_131]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_131]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_131]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190) [spring-web-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) [spring-web-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105) [spring-webmvc-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:878) [spring-webmvc-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:792) [spring-webmvc-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) [spring-webmvc-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040) [spring-webmvc-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) [spring-webmvc-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) [spring-webmvc-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) [spring-webmvc-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:652) [tomcat-embed-core-9.0.38.jar!/:4.0.FR]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) [spring-webmvc-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:733) [tomcat-embed-core-9.0.38.jar!/:4.0.FR]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) [tomcat-embed-core-9.0.38.jar!/:9.0.38]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.38.jar!/:9.0.38]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) [tomcat-embed-websocket-9.0.38.jar!/:9.0.38]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-9.0.38.jar!/:9.0.38]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.38.jar!/:9.0.38]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) [spring-web-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) [spring-web-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-9.0.38.jar!/:9.0.38]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.38.jar!/:9.0.38]
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) [spring-web-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) [spring-web-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-9.0.38.jar!/:9.0.38]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.38.jar!/:9.0.38]
at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:93) [spring-boot-actuator-2.3.4.RELEASE.jar!/:2.3.4.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) [spring-web-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-9.0.38.jar!/:9.0.38]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.38.jar!/:9.0.38]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) [spring-web-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) [spring-web-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-9.0.38.jar!/:9.0.38]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.38.jar!/:9.0.38]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) [tomcat-embed-core-9.0.38.jar!/:9.0.38]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) [tomcat-embed-core-9.0.38.jar!/:9.0.38]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541) [tomcat-embed-core-9.0.38.jar!/:9.0.38]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143) [tomcat-embed-core-9.0.38.jar!/:9.0.38]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [tomcat-embed-core-9.0.38.jar!/:9.0.38]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) [tomcat-embed-core-9.0.38.jar!/:9.0.38]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) [tomcat-embed-core-9.0.38.jar!/:9.0.38]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374) [tomcat-embed-core-9.0.38.jar!/:9.0.38]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) [tomcat-embed-core-9.0.38.jar!/:9.0.38]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) [tomcat-embed-core-9.0.38.jar!/:9.0.38]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590) [tomcat-embed-core-9.0.38.jar!/:9.0.38]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.38.jar!/:9.0.38]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_131]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_131]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.38.jar!/:9.0.38]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_131]
это от моего помпа
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.4.RELEASE</version>
<relativePath></relativePath>
</parent>
...
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-cassandra</artifactId>
<version>3.0.4.RELEASE</version>
</dependency>
РЕДАКТИРОВАТЬ: включая определения POJO
@Table(value = "metatable")
public class MetaDatatype {
@Column @PrimaryKey
private String id;
@Column
private Set<Payment> payments;
@Column(value = "pricerating")
private short priceRating;
@Column
@CassandraType(type = CassandraType.Name.UDT, userTypeName = "announcement")
private BusinessAnnouncement announcement; //This is the only UDT, all others are enums
@Column
private Set<Highlight> highlights;
@Column
private Set<Delivery> deliveries;
@Column(value = "wifiavailable")
private boolean wifiAvailable;
@Column
private Set<Audience> audiences;
@Column(value = "referencetype")
private Config.ReferenceType referenceType;
@Column(value = "referenceid")
private String referenceId;
@Column(value = "addedTimestamp")
private long addedTimestamp;
@Column(value = "pricerating")
private long modifiedTimestamp;
@Column
private MetaType metatype;
@Column
private boolean appointment;
@Column
private List<Seating> seating;
@Column
private List<DisabilityAccess> accesses;
@Column
private List<Parking> parking;
@Column
private Set<Amenities> amenities;
@Column
private Set<Facilities> facilities;
}
Определение пользовательского класса типа данных
@UserDefinedType("announcement")
public class BusinessAnnouncement {
@CassandraType(type = CassandraType.Name.BIGINT)
private long timestamp;
@CassandraType(type = CassandraType.Name.TEXT)
private String message;
}