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, i.e. http://abc.com/customer-50, http://abc.com/customer-51, http://abc.com/customer-52.
Now it become http://abc.com/customer-4d1b4687a6d5437619000000
-
I will need to change all the reference classes from long to objectId.
-
Is it possible to keep the original design (which uses Long id, instead of ObjectId)?
Thanks!
Take a look at
https://code.google.com/p/morphia/source/browse/trunk/morphia/src/main/java/com/google/code/morphia/utils/LongIdEntity.javahttps://github.com/mongodb/morphia/blob/master/morphia/src/test/java/org/mongodb/morphia/utils/LongIdEntity.java (link updated)https://github.com/MorphiaOrg/morphia/blob/master/morphia/src/test/java/xyz/morphia/utils/LongIdEntity.java (updated again)