Reputation: 1
This may not entirely be an appropriate question to ask, but why not I'm curious and I do not know the right places to look for these answers (If y'all have links to said places please do drop them down!).
So say we have Entity A and B, of which A and B has a one-one/one-many relation(may be important, but to simplify they are simply just related)
And I want to retrieve entity B from an instance of entity A. So in other words, retrieveAfromB(). (Which params depends on if its one-one or one-many but for simplicity)
I immediately think of 3 ways that this method could be in:
At this point I am aware that I could have summarized my question down to whether 2. or 3. is more appropriate, and also what should be in an entity's session bean. Please enlighten me and thanks so much!
Upvotes: 0
Views: 43
Reputation: 1521
You are not explicitly saying, but by your language I'll asume you are talking about JPA (Entities, one-to-many).
Entities relations can be modeled both ways. You can have 2 entities and anotate one, both, or even none at all (no matter what kind of dependency). Which approach to choose depends solely on your business case. Does it make more sense retrieving A from B or the other way round?
In any case, you will have a class attribute with getters and setters, because that's what JPA is relying on to automagically manage the entities. About how to model them you have a great blog post from Vlad Mihalcea (Java Champion who contributes to hibernate) about all the relations here:
https://vladmihalcea.com/database-table-relationships/
At the end of each of the relations sections shows a link to another blog post explaining what is the best approach to model that relation.
Upvotes: 0