| 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: 172
|
|
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.
|
 |
 |
|
|
subject: what us mean mappedBy="item" ?
|
|
|