• 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
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

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.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic