Going through the link
http://vladmihalcea.com/hibernate-facts-the-importance-of-fetch-strategy/, I notice two differences in behavior using Hibernate session
directly vs through JPA entity manger.
(1) If I use hibernate session with (5.0.4)
directly instead of through an JPA entitymanager for the "
Use case 3: Selecting a list of Products with an explicit join fetch plan", I still see an extra select getting fired to fetch the company entity that is mapped as EAGER. Is this the expected behavior? If so, this is pretty confusing for the user, since the behavior is not standard across JPA and Hibernate. Are there any plans to standardize this?
(2) Regarding the OneToOne mapping in Product class:
Code:
@OneToOne(mappedBy="product", cascade=CascadeType.ALL, fetch=FetchType.LAZY, optional=false)
private WarehouseProductInfo warehouseProductInfo;
Iam unable to persist the product with hibernate (5.0.4) session
directly. It throws following constraint violation exception
Code:
ERROR 23503: INSERT on table 'WAREHOUSEPRODUCTINFO' caused a violation of foreign key constraint 'SQL160116151600291' for key (0). The statement has been rolled back.
Instead of @PrimaryKeyJoinColumn, I even tried with @MapsId in the WarehouseProductInfo class, even that fails with following exception.
Code:
org.hibernate.id.IdentifierGenerationException: null id generated for:class com.madhu.hibernate.fetchStrategy.WarehouseProductInfo
So wanted to know whether
optional=false is supported or not in hibernate while persisting or am I doing somethig wrong?