This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

what us mean mappedBy="item" ?

 
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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.
 
Ew. You guys are ugly with a capital UG. Here, maybe this tiny ad can help:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic