| I am not allowed to delete my own attachments here. Please ignore the first attachment and take a look at the second file I uploaded. It is based on the hibernate-orm-5 test template. It may seem strange to use a @OneToMany annotation from A to B, as I am referring the primary key of B and it actually is a OneToOne relation. The reason is that the presence of B is optional. I may or may not have an entity in B with the id given in nonPrimaryRelationId. For Hibernate to return optional *ToOne releations as null instead of throwing an exception when accessing the field, the Hibernate proprietary @NotFound(action = NotFoundAction.IGNORE) annotation is required on the field. With this annotation, Hibernate does not support lazy loading unless build time bytecode enhancement is enabled. Our code requires the NotFoundAction.IGNORE annotation, performance considerations require the relationship to be lazy and our build and development environment does not allow us to use build time bytecode enhancement. A common workaround for these restrictions seem to be to map as a *ToMany relation, allowing Hibernate to inject a proxied collection, which when accessed will resolve the lazy binding and hold 0 or 1 element. |