gpt4 book ai didi

java - Cassandra 映射器未映射到该类

转载 作者:行者123 更新时间:2023-12-01 07:02:41 25 4
gpt4 key购买 nike

我正在构建 REST API 并且我有访问器,

    @Accessor
public interface ActiveBidAccessor {
@Query("SELECT * FROM keyspace.active_bid WHERE username = :username")
public Result<ActiveBid> getAllByUsersname(@Param("username") String username);


@Query("SELECT * FROM keyspace.active_bid")
public Result<ActiveBid> getAll();
}

和ActiveBid类

@Table(keyspace = "keyspace", name = "active_bid", readConsistency = "QUORUM", writeConsistency = "QUORUM", caseSensitiveKeyspace = false, caseSensitiveTable = false)
public class ActiveBid {
@PartitionKey
UUID uid;
@ClusteringColumn
@Column(name = "username")
String username;
@Column(name = "project_name")
String projectName;
@Column(name = "project_link")
String projectLink;
@Column(name = "total_bid")
int totalBid;
@Column(name = "user_bid")
long userBid;
@Column(name = "avg_bid")
long avgBid;
@Column(name = "end_date")
Date endDate;

public ActiveBid(UUID uid, String username, String projectName, String projectLink, int totalBid, long userBid,
long avgBid, Date endDate) {
super();
this.uid = uid;
this.username = username;
this.projectName = projectName;
this.projectLink = projectLink;
this.totalBid = totalBid;
this.userBid = userBid;
this.avgBid = avgBid;
this.endDate = endDate;
}

public UUID getUid() {
return uid;
}

public void setUid(UUID uid) {
this.uid = uid;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getProjectName() {
return projectName;
}

public void setProjectName(String projectName) {
this.projectName = projectName;
}

public String getProjectLink() {
return projectLink;
}

public void setProjectLink(String projectLink) {
this.projectLink = projectLink;
}

public int getTotalBid() {
return totalBid;
}

public void setTotalBid(int totalBid) {
this.totalBid = totalBid;
}

public long getUserBid() {
return userBid;
}

public void setUserBid(long userBid) {
this.userBid = userBid;
}

public long getAvgBid() {
return avgBid;
}

public void setAvgBid(long avgBid) {
this.avgBid = avgBid;
}

public Date getEndDate() {
return endDate;
}

public void setEndDate(Date endDate) {
this.endDate = endDate;
}

@Override
public int hashCode() {
return Objects.hashCode(uid, username, projectName, projectLink, totalBid, userBid, avgBid, endDate);
}

@Override
public boolean equals(Object obj) {
if (obj instanceof ActiveBid) {
ActiveBid that = (ActiveBid) obj;
return Objects.equal(this.uid, that.uid) && Objects.equal(this.username, that.username)
&& Objects.equal(this.projectName, that.projectName)
&& Objects.equal(this.projectLink, that.projectLink) && Objects.equal(this.totalBid, that.totalBid)
&& Objects.equal(this.userBid, that.userBid) && Objects.equal(this.avgBid, that.avgBid)
&& Objects.equal(this.endDate, that.endDate);
}
return false;
}

和我的 Jersey 请求映射器以及获取数据的逻辑

@GET
@Path("/get")
@Produces(MediaType.APPLICATION_JSON)
public List<ActiveBid> getTrackInJSON() {
logger.info("LoginApi: Returning the active bid");
List<ActiveBid> activeBidList = new ArrayList<ActiveBid>();

MappingManager manager = new MappingManager(cassDB.getSession());
ActiveBidAccessor activeBidAccessor = manager.createAccessor(ActiveBidAccessor.class);
Result<ActiveBid> activeBidResult = activeBidAccessor.getAllByUsersname("zakir");
for(ActiveBid bid:activeBidResult){
activeBidList.add(bid);
}

return activeBidList;
}

我收到以下错误

Caused by: java.lang.RuntimeException: Can't create an instance of com.xyz.v1.ActiveBid at com.datastax.driver.mapping.ReflectionMapper.newEntity(ReflectionMapper.java:47) at com.datastax.driver.mapping.Result.map(Result.java:40) at com.datastax.driver.mapping.Result.one(Result.java:87) at com.datastax.driver.mapping.Mapper$1.apply(Mapper.java:82) at com.datastax.driver.mapping.Mapper$1.apply(Mapper.java:79) at com.google.common.util.concurrent.Futures$1.apply(Futures.java:713) at com.google.common.util.concurrent.Futures$ChainingListenableFuture.run(Futures.java:861) at com.google.common.util.concurrent.MoreExecutors$SameThreadExecutorService.execute(MoreExecutors.java:297) at com.google.common.util.concurrent.ExecutionList.executeListener(ExecutionList.java:156) at com.google.common.util.concurrent.ExecutionList.execute(ExecutionList.java:145) at com.google.common.util.concurrent.AbstractFuture.set(AbstractFuture.java:185) at com.google.common.util.concurrent.Futures$ChainingListenableFuture$1.run(Futures.java:872) at com.google.common.util.concurrent.MoreExecutors$SameThreadExecutorService.execute(MoreExecutors.java:297) at com.google.common.util.concurrent.ExecutionList.executeListener(ExecutionList.java:156) at com.google.common.util.concurrent.ExecutionList.execute(ExecutionList.java:145) at com.google.common.util.concurrent.AbstractFuture.set(AbstractFuture.java:185) at com.datastax.driver.core.DefaultResultSetFuture.onSet(DefaultResultSetFuture.java:174) at com.datastax.driver.core.RequestHandler.setFinalResult(RequestHandler.java:177) at com.datastax.driver.core.RequestHandler.access$2500(RequestHandler.java:43) at com.datastax.driver.core.RequestHandler$SpeculativeExecution.setFinalResult(RequestHandler.java:792) at com.datastax.driver.core.RequestHandler$SpeculativeExecution.onSet(RequestHandler.java:467) at com.datastax.driver.core.Connection$Dispatcher.channelRead0(Connection.java:1013) at com.datastax.driver.core.Connection$Dispatcher.channelRead0(Connection.java:936) at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304) at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:266) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304) at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304) at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:276) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:263) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:846) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354) at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:112) ... 1 more

有人可以帮我解决这个问题吗?我不知道 Cassandra 会这么难用。

最佳答案

驱动程序不善于报告异常原因。 stacktrace points to this

@Override
public T newEntity() {
try {
return entityClass.newInstance();
} catch (Exception e) {
throw new RuntimeException("Can't create an instance of " + entityClass.getName());
}
}

不幸的是,它吞噬了异常。

尽管如此,阅读该代码,似乎会发生异常,因为您的实体类中没有可访问的无参数构造函数。

添加一个即可

public ActiveBid() {}

文档 here没有明确说明,但他们的所有示例都使用此类构造函数。

关于java - Cassandra 映射器未映射到该类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37600816/

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