Java – JDO best practice: storing objects as their parents or as separate collections?

I have a user and transaction class

Each transaction logically belongs to a user However, I may need to query some transaction subsets (for example, return all transactions of user a, where transaction. Type = 1)

In SQL, I only maintain one transaction Userid field to link it to the user table

>Should I do this in the object world of JDO? Separate the pointer field of the stored transaction object from the user object ID? Or should I only query the corresponding user object and subquery of the transaction of type = 1 (for example)? > If I only query user objects, can I also return those transaction objects that are of interest to a given query (as shown in the previous bullet example)?

Solution

With all due respect, generally speaking, there is no best practice However, for users with transactions in an object-oriented context, I will model the user so that each transaction has a list or transaction set of references to its user objects

In this way, you can get all the transactions of the user, just get the user object, and then get the transaction list from there

On the other hand, you can query transactions that are restricted to specific types of specific users Because each transaction is associated with a user object, you can always get the correct context "free"

Of course, you should consider settings like lazy and eager loading, depending on what happens to entities after retrieval (whether they are used in a process or serialized and transmitted to a remote process, etc.)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>