Please use the google group to ask questions - thanks.

by Manfred 30 Jun 03:36
mappedBy

Hello

why you don't use the mappedBy-Attribute in @OneToOne,@OneToMany, @ManyToMany annotations?
Then you do not have to guess the inverse side.

I also thing it is wrong that you have the JoinColumn in an bidirectional @OneToMany mapping

class User
....
@OneToMany
@JoinColumn(name="user_assigned_id")
List Bug assignedBugs;


class Bug
....
@ManyToOne
User userAssigned;


------------------------------------
I think this is the right way.

class User
....
@OneToMany(mappedBy="userAssigned")
List Bug assignedBugs;


class Bug
....
@ManyToOne
@JoinColumn(name="user_assigned_id")
User userAssigned;


Manfred

02 Jul 09:08
by Rob


why you don't use the mappedBy-Attribute in @OneToOne,@OneToMany, @ManyToMany annotations?
Then you do not have to guess the inverse side.

Why? Because in my opinion its not hard to guess and leaves out one more thing that people need to think about (and possibly get wrong).

Perhaps Ebean has guessed the mappedBy-Attribute incorrectly for you? I'd be interested to hear where this has not worked?

02 Jul 09:20
by Rob

RE: I also thing it is wrong that you have the JoinColumn in an bidirectional @OneToMany mapping

In the case of User no I don't think this is wrong. The reason for the explicit @JoinColumn annotation is that User references Bugs two ways (two DB foreign keys) one for logged bugs and one for assigned bugs.

That is, when there is only one foreign key between two tables Ebean can use that. In this case between user and bug there are 2 foreign keys and we explicitly state which one using the @JoinColumn annotation.

02 Jul 09:49
by Rob

That all said, I think this is a bug in Ebean (and I think you are right here)... certainly your note is consistent with the spec, which suggests annotated beans consistent with the spec will not be handled correctly by Ebean (which makes it a bug in Ebean).

So, in our example with the User and Bug beans... the spec examples use a mappedBy attribute and Ebean has been using explicit joins (via @JoinColumn in our example).

This will generally be an issue when two Beans are related in two or more ways (User.loggedBugs, User.assignedBugs , Bug.loggedUser, Bug.assignedUser in our example).

02 Jul 09:54
by Rob

Create a New Topic

Title:
Body:
 
Introduction User Guide (pdf) Install/Configure Public JavaDoc Whitepapers
General Database Specific Byte Code Deployment Annotations Features
Top Bugs Top Enhancements
woResponse