wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes what us mean mappedBy= Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "what us mean mappedBy="item" ?" Watch "what us mean mappedBy="item" ?" New topic
Author

what us mean mappedBy="item" ?

Samanthi perera
Ranch Hand

Joined: Jan 08, 2010
Posts: 510
this is from manning action ejb 3 book.page no 245


i am refering to this line @OneToMany(mappedBy="item")
what us mean mappedBy="item" ?
Uppala Ramana
Greenhorn

Joined: Jan 14, 2010
Posts: 14
i am refering to this line @OneToMany(mappedBy="item")
what us mean mappedBy="item" ?


Samanthi,

The mappedBy element identifies the inverse side of a relationship.

The inverse side of the bidirectional relationship (OneToOne,OneToMany,ManyToMany) refer to its owining side by using the mappedBy element.

In your example, mappedBy="item" is the inverse side of the relation that is Item-> Bids and Bid->Item is the Owning side.

To fetch Bid from object from the Item class, JPA uses the attribute or property specified in the mappedBy element.


Thanks,
Ramana.


Ramana Uppala
SCJA,SCJP
Samanthi perera
Ranch Hand

Joined: Jan 08, 2010
Posts: 510
still i don't understood what you said.
what is you mean by owning?
Jose Ayerdis
Ranch Hand

Joined: Sep 14, 2008
Posts: 30
well mappedBy anotation is very simple let me give you this sceneraio:

I have a Vehicle and Driver POJO's both represent entities on the Database both of them are mapped like this:




As you can see the mappedBy is the refering to a "transportista" object in Vehicle class which said something like this....

"This Set of Vehicle is OneToMany relationship with the class (Vehicle) and do a mapped Inverse mapping with an object named transportista"

So it goes to transportista and gets this

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "id_transportista", nullable = false)
private Driver transportista;


you'll see now hibernate does not have to guess about the reference and that is inverse mapping..............
Christian Dillinger
Ranch Hand

Joined: Jul 20, 2009
Posts: 188
If you have a bi-directional relation between two classes Hibernate "thinks" it has to maintain both sides of relation. So each operation on the relation would lead to two SQL-statements. If you declare one side as "inverse" (by using mappedBy), Hibernate ignores changes made on that side.

I recommend reading "Java Persistence with Hibernate" which is a really great book about Hibernate. All the questions on Hibernate you posted are answered in that book.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what us mean mappedBy="item" ?
 
Similar Threads
EJB3 Entity Relationship
@OneToMany - Is thi bidirectional always?
what is mean mappedBy
Using @JoinColumn VS not using @JoinColumn
CascadeType.PERSIST not working