简体   繁体   中英

MongoDB and Morphia - Traditionnal id (Long) instead of ObjectId

Background:

My REST service project was started up by using Hibernate. I use id (Long) in domain class as part of the identifier in rest url, for example:

http://abc.com/customer-50 , where 50 is the Long id.

The Hibernate Annotated class is as below:

public class Customer {
@Id
@GeneratedValue
private Long id;
}

Now I need to migrate our design to Mongodb. The natural choice is using Morphia, which is an entity framework.

Problem: In Morphia, the id field is ObjectId

@Id private ObjectId id;

This will cause problem because: 1. It is not auto-increment, ie http://abc.com/customer-50 , http://abc.com/customer-51 , http://abc.com/customer-52 .

Now it become http://abc.com/customer-4d1b4687a6d5437619000000

  1. I will need to change all the reference classes from long to objectId.

  2. Is it possible to keep the original design (which uses Long id, instead of ObjectId)?

Thanks!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM