Description
I have two entities: User and Account.
Each user has one account. So the relationship is @OnetoOne and mandatory from user's side.
On the other hand some accounts belong not to users, but to companies. So from the account's side it's @OnetoOne but optional.
I've modeled it in this way:
class User {
@OnetoOne(optional = false)
Account account;
}
class Account {
@OnetoOne(mappedBy = "account",optional = true)
User user;
}
Generated schema is just what I need (account field in User is NOT NULL).
The problem is that when I'm fetching Account (just with .find(), without additional .fetch() ) ebean makes JOIN of the user, not the LEFT OUTER JOIN although on the account's side the relationship is optional. It only starts making LEFT OUTER JOIN if I make it optional also on user's side. But it this case I'm loosing NOT NULLity of the account_id field.
So the question is: how can I enforce LEFT OUTER JOIN on one side while keeping NOT NULLity on the other side? Adding additional @column(nullable=false) annotation to account field doesn't affect the schema.
Activity