Musician 's reason for being is to contain data. This type of class is sometimes known as a DTO, or data transfer object. DTOs are a common feature of software development. While they hold many kinds of data, they do not contain any business logic.
Persisting data objects is a ubiquitous challenge in software development. One way to save an instance of the Musician class to a relational database would be to use the JDBC library. JDBC is a layer of abstraction that lets an application issue SQL commands without thinking about the underlying database implementation. The code in Listing 2 is fairly self-documenting. The georgeHarrison object could come from anywhere front-end submit, external service, etc.
The fields on the object are then used to supply the values of an SQL insert statement. In order to modify the database, you first need to create an SQL query that maps from your Java object to the tables in a relational database. You then have to modify the SQL whenever an object signature change. Listing 3 replaces the manual SQL from Listing 2 with a single line, session. From then on, the SQL conversion is handled by the framework, so you never have to leave the object-oriented paradigm.
The magic in Listing 3 is the result of a configuration , which is created using JPA's annotations. Developers use annotations to inform JPA which objects should be persisted, and how they should be persisted.
Persistent objects are sometimes called entities. Attaching Entity to a class like Musician informs JPA that this class and its objects should be persisted. Like most modern frameworks, JPA embraces coding by convention also known as convention over configuration , in which the framework provides a default configuration based on industry best practices.
To reduce the burden of writing codes for relational object management of an enterprise application, a programmer follows the JPA Provider framework an implementation of JPA , which allows easy interaction with the database instance. In a relational database, the relationships between the two tables are defined by foreign keys. In JPA, we deal with entity objects that are Java representations of database tables. So we need a different way of establishing a relationship between two entities.
The OneToOne annotation is used to define a one-to-one relationship between two entities. For example, you may have a User entity that contains a user's name, email, and password, but you may want to maintain additional information about a user such as age, gender, and favorite color in a separate UserProfile entity.
The OneToOne annotation facilitates breaking down your data and entities this way. The User class below has a single UserProfile instance. The UserProfile maps to a single User instance. Associations : Relational models cannot determine multiple relationships while looking into an object domain model.
Data navigation : Data navigation between objects in an object network is different in both models. Java Persistence API is a collection of classes and methods to persistently store the vast amounts of data into a database which is provided by the Oracle Corporation.
Here the required framework is taken over by JPA. Earlier versions of EJB, defined persistence layer combined with business logic layer using javax. Next came EJB 1. EJB 2. JDO obtained somewhat of a "cult" following of several independent vendors such as Kodo JDO, and several open-source implementations, but never had much success with the big Java EE vendors.
This led the EJB 3.
0コメント