Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

what us mean mappedBy="item" ?

 
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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" ?
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Samanthi perera
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
still i don't understood what you said.
what is you mean by owning?
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..............
 
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic