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 @ 2024-03-29 11:52  东北大亨  阅读(72)  评论(0编辑  收藏  举报