What if the user did not set the NOT NULL on the database side and the FK value is actually null. If we assign a Proxy, and they use a != null check, that will fail since Hibernate no longer mirrors what there's on the database side. Just to give you a quote from the JPA spec related to optional for @Basic properties:
This optional flag is validated at runtime after we get the value from the DB, so an exception is thrown if the model is not synchronized with the DB. That being said, only bytecode enhancement can solve this problem while the behavior is consistent in regards to how optional attributes behave as well. |