About Me

My photo
"Enoughtheory.com" had its humble beginning in the year 2011 by ( Founder of Enoughtheory.com ) Mr Ravi Kant Soni , an Enterprise Java and Spring Framework Specialist, with a bachelor degree (B.E) in Information Science and Engineering from Reva Institute of Technology at Bangalore. He has been into the software development discipline for many years now. Ravi has worn many hats throughout his tenure, ranging from software development, designing multi-tenant applications, integration of new technology into an existing system, to his current love of writing a Spring Framework book. Currently, he is a lead engineer at HCL Technology. Ravi has focused on Web and Enterprise development using Spring Framework for most of his career and has been extensively involved in application design and implementation. He has developed applications for Core-Bank, HR and Payroll System, and e-Commerce systems using Spring Framework. Ravi Kant Soni is author of book "Learning Spring Application development" http://learningspringapplicationdevelopment.com

Tuesday, 8 November 2011

Java Persistence/Relationships


  • A relationship is a reference from one object to another.
  •  In Java, relationships are defined through object references (pointers) from a source object to the target object. 
  • In a relational database relationships are defined through foreign keys. The source row contains the primary key of the target row to define the relationship (and sometimes the inverse). A query must be performed to read the target objects of the relationship using the foreign key and primary key information.
  • In Java, if a relationship is to a collection of other objects, a Collection or array type is used in Java to hold the contents of the relationship. In a relational database, collection relations are either defined by the target objects having a foreign key back to the source object's primary key, or by having an intermediate join table to store the relationship (both objects' primary keys).

JPA Relationship Types

  1. OneToOne - A unique reference from one object to another, inverse of a OneToOne.
  2. ManyToOne - A reference from one object to another, inverse of a OneToMany.
  3. OneToMany - A Collection or Map of objects, inverse of a ManyToOne.
  4. ManyToMany - A Collection or Map of objects, inverse of a ManyToMany.
  5. Embedded - A reference to a object that shares the same table of the parent.
  6. ElementCollection - JPA 2.0, a Collection or Map of Basic or Embedable objects, stored in a separate table.

No comments:

Post a Comment