Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect join with @OneToOne optional on one side and NOT optional on other side #166

Closed
rbygrave opened this issue Jul 9, 2014 · 3 comments
Assignees
Labels
Milestone

Comments

@rbygrave
Copy link
Member

rbygrave commented Jul 9, 2014

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.

@rbygrave rbygrave added this to the 4.1.2 milestone Jul 9, 2014
@rbygrave rbygrave added the bug label Jul 9, 2014
@rbygrave rbygrave self-assigned this Jul 9, 2014
rbygrave added a commit that referenced this issue Jul 9, 2014
@rbygrave rbygrave closed this as completed Jul 9, 2014
@JFCote
Copy link

JFCote commented Apr 11, 2016

Is there a way to get around this bug in version prior to 4.1.2?? I'm using Play Framework 2.3 and the version of Ebean ORM used is 3.3.4 and I can't change it. I have the exact same problem.

@rbygrave
Copy link
Member Author

Version 3.x is very old and 4.x had significant change based on a change to the enhancement.

@JFCote
Copy link

JFCote commented Apr 12, 2016

yeah I know but still I was hoping that something could be done instead of migrating to the new Play Framework which is a nightmare each time. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants