| I just explained it above, but lets look at it in more concrete terms. Given the following model:
@Entity
@Table(name="companies")
class Company {
@Id
public Integer id;
...
}
@Entity
@Table(name="orders")
class Order {
@Id
public Integer id;
@JoinColumn(name="cust_id")
@ManyToOne(fetch = FetchType.LAZY)
@NotFound(action=NotFoundAction.IGNORE)
public Company customer;
...
}
Consider calling session().get( Order.class, 1 )... At this point Hibernate needs to load the data from orders table:
select o.id, o.cust_id, ... from orders o where o.id = 1
and use it to build a Order object. At this point it needs to create a reference to set Order#customer - a non-null reference for a logically null value is unacceptable. With a normal FK, this is easy : if cust_id (the FK value) is null we know that the association is null so we set Order#customer to null; if cust_id is not null we know the association is not null so we can create the proxy reference and set it on Order#customer. With @NotFound, it is not that simple. We can never know whether a given cust_id value indicates null or non-null without checking the companies table to see if the cust_id value had any matching companies.id value. If this just happens silently then yes I think there are things we can do, like log a warning. |