Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Aphorismen
Applications
Business Economics & Admin.
My Computers
Cooking
Devices
Folders
Food
Hardware
Infos
Software Development
Sports
Operation Instructions
Todos
Test
Help
Glossary
Community portal
adaptions
Sidebar anpassen
Wiki RB4
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
JavaJEEJPA
(section)
Page
Discussion
English
Read
Edit
View history
Toolbox
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=Relationships= Multiplicities are of the following types: one-to-one, one-to-many, many-to-one, and many-to-many. The direction of a relationship can be either '''bidirectional''' or '''unidirectional'''. A '''bidirectional''' relationship can have an '''owning''' side and an '''inverse''' side, otherwise a mapping table will be created because it is treated as two unidirectional relationships (another explanation is that can be interpreted as a bag which is a bag. A bag is a collection which can have duplicates but is unordered). * The '''owning''' side of the relation tracked by Hibernate is the side of the relation that owns the foreign key in the database (this represents a foreign key on the n-side of the relationship, see [https://stackoverflow.com/questions/2749689/what-is-the-owning-side-in-an-orm-mapping here]). * The '''inverse''' (non-owning) side must use the mappedBy element. There is a god description [https://thorben-janssen.com/ultimate-guide-association-mappings-jpa-hibernate/ here]. '''Bidirectional''' relationships must follow these rules. * The inverse side of a bidirectional relationship must refer to its owning side by using the mappedBy element of the @OneToOne, <code>[[#javax.persistence.OneToMany|@OneToMany]]</code>, or <code>[[#javax.persistence.ManyToOne|@ManyToOne]]</code> annotation. * For many-to-many bidirectional relationships, either side may be the owning side. * On the one side there should be a addXXX() and removeXXX() method which calls the parent-setting of the added/removed XXX object * The implementation of the relationship setting is also depending on the cascade setting (see [https://stackoverflow.com/questions/2749689/what-is-the-owning-side-in-an-orm-mapping here]). * If an ordered many relationship is needed the [[#javax.persistence.OrderColumn|@OrderColumn]] annotation is needed. * the [[#javax.persistence.JoinColumn|@JoinColumn]] is optional, if it is not there Hibernate uses a default naming strategy. In uni-directional relationships it seems that it avoids an additional association table. '''Unidirectional''' is a relation where one side does not know about the relation. A unidirectional relationship has only an owning side. A unidirectional relationship is represented as a join table because the n-side could be referenced by multiple objects on the 1-side of the relationship. Entity relationships often depend on the existence of another entity. When we delete a parent entity, the child entities should also get deleted. '''Cascading''' is the way to achieve this. When we perform some action on the target entity, the same action will be applied to the associated entity. Orphan removal means that if an entity is deleted from a relationsship and orphan removal is true, than the orphan will be deleted. ==One-To-Many, Many-To-One== * the one side is sometimes called '''parent''', the many side '''child''' or '''children''' * child table contains a foreign key to the primary key of the parent table, hence the many side is always the owning side of the relationship. * bidirectional <code>[[#javax.persistence.OneToMany|@OneToMany]]</code> needs a <code>[[#javax.persistence.ManyToOne|@ManyToOne]]</code> association on the other side. * The many side of many-to-one bidirectional relationships must not define the mappedBy element. * You should always provide methods <code>parent.addChild()</code> and <code>parent.removeChild()</code> which are used to set the child site whenever you are working with a bidirectional association. void addChild(child) { children.add(child); child.setparent(this); } * Itβs good practice to override equals and hashCode for the child entity in a bidirectional association. ==Fetching== The default depends on the cardinality of the relationship. All to-one relationships use FetchType.EAGER and all to-many relationships FetchType.LAZY. ==Persistance Unit== A '''persistence unit''' is the group of classes which is managed by one entity manager and references one database. It also indicates which transaction type is to be used when the database operations occur. The persistence unit consists of three main parts. * entity metadata * persistence unit descriptor ** persistence provider ** database connection ** transaction type * persistence manager factory A persistence unit is defined in [[#persistence.xml|persistence.xml]].
Summary:
Please note that all contributions to Wiki RB4 may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Uwe Heuer Wiki New:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width