mongo Cannot autogenerate id of type java.lang.Object for entity of type com.tycoon.frame.entity.Transaction!

1、mongo集群存入实体类数据报错 :  Cannot autogenerate id of type java.lang.Object for entity of type com.tycoon.frame.entity.Transaction!

2、通过排查实体类 Transaction 的 定义的Object 为java Class Object is the root of the class hierarchy. Every class has Object as a superclass. All objects,

   修改错误前

@Data
@Document(collection = "Transaction")
public class Transaction{

// 单机情况下使用没问题
private Object _id;

......
}
正确写法应该写为:
import org.bson.types.ObjectId;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.List;
@Data
@Document(collection = "Transaction")
public class Transaction{
//  Cannot autogenerate id of type java.lang.Object for entity of type com.tycoon.frame.entity.Transaction
// private Object _id;
    private ObjectId _id; # 正确写法

......
}
posted @   东北大亨  阅读(148)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 通过 API 将Deepseek响应流式内容输出到前端
· 因为Apifox不支持离线,我果断选择了Apipost!
历史上的今天:
2019-03-29 idea 全部报错找不到包
点击右上角即可分享
微信分享提示