Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
JPA Relationship 
 

In this section, you will know about the jpa relationship. JPA supports the relationship between entities.

 

JPA Relationship

                                    

In this section, you will know about the jpa relationship. JPA supports the relationship between entities.

There are following types of relationship:

  1. One-to-one
  2. One-to-many
  3. Many-to-one
  4. Many-to-many
  5. Many-to-many Retrieve data

JPA relationships are not bi-directional. JPA annotations are added to define the relationship. If, you want to make a relationship bi-directional to use a special attribute.

  1. One-to-one: A OneToOne relation mapping to a single-value association to another entity. It has one-to-one multiplicity and infers the associated target entity from the type of the object being referenced.

    Use of the @OneToOne Annotation:
    1. Configure the fetch type to LAZY
    2. Configure the mapping to forbid null values (for non-primitive types) in case null values are inappropriate for your application
    3. Configure the associated target entity if it cannot be inferred from the type of the object being referenced
    4. Configure the operations that must be cascaded to the target of the association. For example, if the owning entity is removed, ensure that the target of the association is also removed
  2. One-to-many: JPA defines a OneToMany mapping for a many-valued association with one-to-many multiplicity.

    Use of the @OneToMany Annotation:
    1. Configure the fetch type to EAGER
    2. Configure the associated target entity because the Collection used is not defined using generics
    3. Configure the operations that must be cascaded to the target of the association: for example, if the owning entity is removed, ensure that the target of the association is also removed
    4. Configure the details of the join table used by TopLink JPA for uni-directional one-to-many relationships
  3. Many-to-one: JPA defines a ManyToOne mapping for a single-valued association to another entity class that has many-to-one multiplicity.

    Use the @ManyToOne Annotation to:
    1. Configure the fetch type to LAZY
    2. Configure the mapping to forbid null values (for non-primitive types) in case null values are inappropriate for your application
    3. Configure the associated target entity if it cannot be inferred from the type of the object being referenced
    4. Configure the operations that must be cascaded to the target of the association: for example, if the owning entity is removed, ensure that the target of the association is also removed
  4. Many-to-many: JPA defines a @ManyToMany mapping for a many-valued association with many-to-many multiplicity.

    Use of the @ManyToMany annotation:
    1. Declare the cardinality of the relationship
    2. Configure the fetch type to EAGER
    3. Configure the mapping to forbid null values (for non-primitive types) in case null values are inappropriate for your application
    4. Configure the associated target entity because the Collection used is not defined using generics
    5. Configure the operations that must be cascaded to the target of the association; for example, if the owning entity is removed, ensure that the target of the association is also removed

There are following types of cascade:

  1. CascadeType.PERSIST: When we persist and entity all the entities held in this field persist too. If you want to persist an entity and the fields dont use it fails.
  2. CascadeType.REMOVE: When we delete an entity all the entities held in this field delete too.
  3. CascadeType.REFRESH: When we refresh an entity all the entities held in this field refresh too.
  4. CascadeType.MERGE: When we merde an entity all the entities held in this flied merged too

The property cascade = CascadeType.ALL indicates that when we persist, remove, refresh or merge this entity all the entities held in this field would be persist, remove, delete or update.

Download JPA Annotation Relationship Application

                                    

» View all related tutorials
Related Tags: c table io ip this tab record records to relationship sh e man in m relation relations many-to-one rel s

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.