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.

Persistence Entities


  • Persistent Data normally refers to permanent data in an application.
  • The state of these data is made permanent by storing them in a persistent medium like database, files or a disk tape.
  • In JPA terms, these persistent data are referred as ENTITIES.
  • An entity refers to a logical collection of data that can be stored or retrieved as a whole.
For example, in a banking application, Customer and BankAccount can be treated as entities. Customer name, customer address etc can be logically grouped together for representing a Customer entity.
  • some unique characteristics
  1. The property of persistability deals with the storing and retrieving of entity from and to a persistent medium like database.
  2. Identity property is usually used to identity one unique entity among multiple entities (or multiple entity instances) in a database.
  3. All the CRUD operations (Create, Update and Delete) for entity objects will occur within a transactional context and it is one of the major characteristic for an entity object as the real state of an entity depends whether a transaction completes (commits/fails) or not.

Java Persistence


  • The Java Persistence Architecture API (JPA) is a Java specification, not a productit ; & cannot perform persistence or anything else by itself.
  • JPA is just a set of interfaces, and requires an implementation. 
  • For accessing, persisting, and managing data between Java objects / classes and a relational database.
  • JPA was defined as part of the EJB 3.0 specification , for Object to Relational Mapping (ORM) in the Java Industry.
  • JPA allows POJO (Plain Old Java Objects) to be easily persisted without requiring the classes to implement any interfaces or methods.
  •  JPA also defines a runtime EntityManager API for processing queries and transaction on the objects against the database.
  • JPA defines an object-level query language, JPQL, to allow querying of the objects from the database.
  • This API has borrowed many of the concepts and standards from leading persistence frameworks like Toplink (from Oracle) and Hibernate (from JBoss).
  • One of the great benefits of JPA is that it is an independent API and can nicely integrate with J2EE as well as J2SE applications.
  • POJO – Plain Old Java Object is a term used to refer Java objects that do not extend or implement some specialized classes. 

    Therefore, all normal Java objects are POJO’s only. The following classes are not POJO classes.
    
     class MyServlet extends HttpServlet {}
     class MyRemote implements SessionBean {}

What is a database?


  • database is a program that stores data.
  • There are many types of databases: flat-file, hierarchical, relational, object-relational, object-oriented, xml, and others. 
  • Relational databases are characterized by the SQL (structured query language) standard to query and modify the database, their client/serverarchitecture, and relational table storage structure.
  • Their client/server architecture allows the client programming language to be decoupled from the server, allowing the database server to support interface APIs into multiple different programming languages and clients.
  • The main relational databases used today are, OracleMySQL (Oracle), PostgreSQLDB2 (IBM), SQL Server (Microsoft).

Monday, 7 November 2011

What is Java persistence?


  • Java persistence could be defined as storing anything to any persistence store in the Java programming language.
  • There are many ways to persist data in Java, to name a few, JDBCserialization, file IO, JCAobject databases, or XML databases.
  • Most things that you do on a computer or web site that involve storing data, involve accessing a relational database.
  • Relational databases are the standard persistence store for most corporations from banking to industrial.
  • There are many things that can be stored in databases from Java. Java data includes strings, numbers, dates and byte arrays, images, XML and Java objects.
  • Many Java applications use Java objects to model their application data
  • Java is an Object Oriented language, storing Java objects is a natural and common approach to persisting data from Java.

Monday, 29 August 2011

Entity RelationShip

  1.  @OneToMany   @ManyToMany
    1. The Object Should be ArrayList
  2.   @ManyToOne  @OneToOne
    1. Normal Object