Hi there. I have a question about subject. Consider the following hypothetical example.
Code:
@Entity
public class Order {
private Customer customer;
public void setCustomer(Customer customer) {
this.customer = customer;
}
public Customer getCustomer() {
if (customer == null)
return Customer.createNullCustomer();
else
return this.customer;
}
}
@Entity
public class Customer {
static Customer createNullCustomer() {
return new NullCustomer();
}
public boolean isNull() {
return false;
}
}
public class NullCustomer extends Customer {
public boolean isNull() {
return true;
}
}
@Entity
public class Item{
private Customer customer;
private Order order;
public void doSomething() {
this.customer = order.getCustomer();
}
}
Suppose, we have NullCustomer in Item. I want to persist Item instance in such way, that there will be null in database for customer if it's NullCustomer. How can I do that without creating custom user type?