Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In my experience you're doing it exactly as it is commonly done. My question would be more about the structure (I expect there is a lot more going on than the sample provided above) as to why you want to manipulate the Account directly from the Group. </p> <p>I also question whether this is a OneToMany or a ManyToMany situation (usually multiple accounts can belong to a single group and multiple groups can belong to a single account but it is all in the semantics of your particular accounting scheme...) anyway: you're doing it right, and though I question (in this exact case) why you would want to directly manipulate the account (unless it is Lazily loaded) this is entirely fine. </p> <p>[You may need to add some Cascade rules so that it persists properly depending on your configuration.]</p> <p>You should note that by mapping to the Account you have effectively added it to the List of the Account. When the database next queries to create that list it will populate the list by finding the references from the Account entity.</p> <p>In short-> </p> <pre><code>public void Group.setAccounts(Account a) { this.account = a; } </code></pre> <p>is effectively equivalent to what you are doing above. The database will query and populate the List with something akin to:</p> <pre><code>//Pseudo SQL SELECT g.id FROM Group g WHERE g.account_id = :account_id </code></pre> <p>Thus, aside from the lazy load (something you may or may not want) adding to the groups is unnecessary as the List is defined by the query. </p> <p>(Don't make it too hard, it look simple. I hope the long explanation gives you an idea of what's happening in the JPA)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload