Reputation: 457
what is different from this syntax on JPA
q.setMerchant(em.find(Merchant.class, m.getId()));
between
q.getMerchant.setId(m.getId());
Upvotes: 1
Views: 204
Reputation: 214
Your first example sets the merchant of q to the merchant found with the I'd m.getId() . Your second example retrieves the merchant returned from the call to q and then sets it's id to m.getId() . It does NOT set the merchant on q to the merchant identified my m.getId()
Upvotes: 1
Reputation: 1966
In the first case, the Merchant object becomes an attached entity and in the second case if it is not already attached it stays detached.
Upvotes: 2