I have the entity model:
@Entity
public class UserEntity {
@Id
@Column(name = "id")
private String id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "restaurant_id", nullable = false)
@LazyToOne(value = LazyToOneOption.NO_PROXY)
private RestaurantEntity restaurant;
// getters & setters
}
Hibernate produces the one sql query for the following code and it's the expected behavior:
// this code gets user entry with specified user id
// as result you can see the single sql query in hibernate logs.
entityManager.find(UserEntity.class, userId);
But in case of the entity code is instrumented (by hibernate-enhance-maven-plugin) , hibernate loads all lazy relations, so the same code produces two query: One for getting user with id, the secode for getting restaurant (despite the relation is lazy).
Do you have any ideas?