Home > Blockchain >  How to use UUID in MongoDB Java (JPA)
How to use UUID in MongoDB Java (JPA)

Time:06-10

I know how to generate UUID in a relational database.

@Id
@GeneratedValue(generator = "UUID")
@GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator")
@Column(name = "id", updatable = false, nullable = false)
private UUID fileId;

However, GeneratedValue and GenericGenerator cannot be imported.

How can I do it in Mongo?

CodePudding user response:

Mongo has ObjectId, It is a powerful data type that is incredibly useful as a unique identifier in MongoDB Documents.

For more information please check https://www.mongodb.com/developer/products/mongodb/bson-data-types-objectid/

  • Related