What exactly is the difference in the following two declarations
B is the owning side
@Entity
class A {
@Id int id;
@OneToOne
B b;
}
@Enti
As other have pointed out, you are wrong about which side is the owning side in your examples. With owning side we mean owning the relationship from an OO perspecitve, in practise that quite often ends up being the opposite of how it is or will be generated in the db if one uses a rdbm as persistence provider.
In normal circumstances the OO model makes it quite clear which sides is the owning side. For example an Order has OrderLines. If we delete an Order all Orderlines should be deleted. If we delete an OrderLine the Order possibly still has a right to existence. Hence, the Order is the owning side.
For a more concrete and excellent example, on the effects of which side is the owning side, I refer to @JB Nizet answer.
According to section 2.9 of the JPA 2.0 spec:
For one-to-one bidirectional relationships, the owning side corresponds to the side that contains the corresponding foreign key.
But in the same section we also have:
In addition, this specification also requires support for the following alternative mapping strategies: [..] The mapping of unidirectional and bidirectional one-to-one relationships, bidirectional many-to-one/one-to-many relationships, and unidirectional many-to-one relationships by means of join table mappings.
A bit futher down in the same section it continues with:
Additional mapping annotations (e.g., column and table mapping annotations) may be speci- fied to override or further refine the default mappings and mapping strategies described in Section 2.10. Some implementations make use of that to allow the FK of a birectional OneToOne to be in the target table.
To read some about some strategies to solve that scenario, see: An almost good explaination
I haven't checked but I do hope and believe that 2.1 will remove the first quote. Since the actual database structure should put as little limit as possible on how we can model data as entities.