usually, java developers convert objects between layers. for example from application domain objects to persistent entities and vice versa. however, apache cayenne use ObjectId to represent keys in database, and it's a combination of entity name and keys in map, so I would like to know what is the best practice to map ObjectId to other layers. In fact, I am using ObjectId in my POJO right now, but I don't know if it is applicable. Thanks...
Asked
Active
Viewed 62 times
0
-
There's no single right answer. It depends on your app. If you could explain the purpose of that POJO layer, it will be easier to give advice about the id. – andrus_a Mar 30 '21 at 07:02
-
the purpose of that POJO layer is used to generate JSON for restful services. I need id in POJOs because I may use values of POJO to update database. I am used to JPA and I usually have one or multiple attributes in POJO to represent key, but ObjectId is a little different because it's entity name + map. So the convenient way for me is to use ObjectId in POJO, just want to know if it is applicable. Thanks – robinly Mar 31 '21 at 13:55
1 Answers
0
Since your POJOs goal is to mirror JSON, the main consideration here should be your REST API convenience for the consumer.
While on the Java side, having a semi-opaque ObjectId is often a good idea, in JSON REST API I would suggest to "unpack" the ID map into individual properties. Hence the POJO would also need those properties.

andrus_a
- 2,528
- 1
- 16
- 10