1 Mapping Persistent Objects Entities represent data in the database, so changes to an entity bean result in changes to the database. That's ultimately.

Slides:



Advertisements
Similar presentations
Introduction to NHibernate By Andrew Smith. The Basics Object Relation Mapper Maps POCOs to database tables Based on Java Hibernate. V stable Generates.
Advertisements

Road Map Introduction to object oriented programming. Classes
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Basic (Flat) Relational Model.
Entities and Persistence. Entity Beans Topics to be Covered: Entities are POJOs Managed/Unmanaged Entities Persistence Unit EntityManager Basic Relational.
Terms and Rules Professor Evan Korth New York University (All rights reserved)
Introduction to Structured Query Language (SQL)
Phonegap Bridge – File System CIS 136 Building Mobile Apps 1.
The Java Persistence API Edel Sherratt. Contents Revisit applications programming Using Java Persistence API.
CSE446 S OFTWARE Q UALITY M ANAGEMENT Spring 2014 Yazılım ve Uyguluma Geliştirme Yöneticisi Orhan Başar Evren.
Training - Day 3 OJB. What is OR Mapping? OR Mapping is the mapping of relational database tables to objects (Java Objects in our case) Many OR Mapping.
Maven for building Java applications By Nalin De Zoysa
1 Lecture 17 George Koutsogiannakis/SUMMER 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES.
1 The Seven Relationship Types Seven types of relationships can exist between entity beans. There are four types of cardinality: one-to- one, one-to-many,
1 The JNDI ENC and Injection Every EJB container that is deployed in an application server has its own personal internal registry called the Enterprise.
JPA Java Persistence API. Introduction The Java Persistence API provides an object/relational mapping facility for managing relational data in Java applications.
IS-907 Java EE JPA: Simple Object-Relational Mapping.
© 2007 by Prentice Hall (Hoffer, Prescott & McFadden) 1 Introduction to SQL.
Lecture 7 Integrity & Veracity UFCE8K-15-M: Data Management.
Java Classes Appendix C © 2015 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
1 Part 2: EJB Persistency Jianguo Lu. 2 Object Persistency A persistent object is one that can automatically store and retrieve itself in permanent storage.
Topic : JPA Kaster Nurmukan. Overview of JPA EntityManager.
Chapter 5: Part 1: DDL STRUCTURED QUERY LANGUAGE (SQL)
M1G Introduction to Database Development 2. Creating a Database.
1 Architectural Overview For application developers, assembling enterprise beans requires little or no expertise in the complex system-level issues that.
Hibernate 3.0. What is Hibernate Hibernate is a free, open source Java package that makes it easy to work with relational databases. Hibernate makes it.
Entity-Relationship (ER) Modelling ER modelling - Identify entities - Identify relationships - Construct ER diagram - Collect attributes for entities &
Agenda Object Oriented Programming Reading: Chapter 14.
1 Persistence in Java Enterprise Container Managed Persistence Application Managed Persistence Michael Brockway Sajjad Shami CG0165: Advanced Applications.
Peyman Dodangeh Sharif University of Technology Fall 2013.
Sadegh Aliakbary Sharif University of Technology Spring 2011.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Chapter 10 Designing the Files and Databases. SAD/CHAPTER 102 Learning Objectives Discuss the conversion from a logical data model to a physical database.
A U.S. Department of Energy Office of Science Laboratory Operated by The University of Chicago Argonne National Laboratory Office of Science U.S. Department.
Middleware Technology (J2EE/EJB) Entity Bean (JBoss EJB 3.0 tutorial)
Chapter 7: Characters, Strings, and the StringBuilder.
Session 11 Creating Tables and Using Data Types. RDBMS and Data Management/Session 11/2 of 40 Session Objectives Define the data types and list the categories.
Enterprise Java v041109Container Managed Relationships1 Container Managed Relationships (CMR) Source: “Enterprise JavaBeans, 3rd Edition”, Richard Monson-Haefel.
CSE314 Database Systems Lecture 3 The Relational Data Model and Relational Database Constraints Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
SQL ACTION QUERIES AND TRANSACTION CONTROL CS 260 Database Systems.
Object Serialization.  When the data was output to disk, certain information was lost, such as the type of each value.  If the value "3" is read from.
JAVA BEANS JSP - Standard Tag Library (JSTL) JAVA Enterprise Edition.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Session 1 Module 1: Introduction to Data Integrity
Data Design and Implementation. Definitions Atomic or primitive type A data type whose elements are single, non-decomposable data items Composite type.
The Java Persistence API ©SoftMoore ConsultingSlide 1.
v110912Java Persistence: EntityManager2 Overview Earlier versions of EJB Specification defined the persistence layer –javax.ejb.EntityBean Java EE 5 moved.
IS-907 Java EE Introduction to JPA. Java Persistence API A framework for using relational databases in Java programs mapping between tables and classes,
Hibernate Thuy, Le Huu. Pentalog VN. Agenda Hibernate Annotations Improving performance – Lazy loading – Fetching Strategies – Dynamic insert, dynamic.
 Data Type is a basic classification which identifies different types of data.  Data Types helps in: › Determining the possible values of a variable.
1 Entity Callbacks and Listeners When you execute EntityManager methods like persist( ), merge( ), remove( ), and find( ), or when you execute EJB QL queries,
CSC314 DAY 8 Introduction to SQL 1. Chapter 6 © 2013 Pearson Education, Inc. Publishing as Prentice Hall SQL OVERVIEW  Structured Query Language  The.
CS520 Web Programming Object-Relational Mapping with Hibernate and JPA (I) Chengyu Sun California State University, Los Angeles.
CS 440 Database Management Systems Stored procedures & OR mapping 1.
CHAPTER 9 File Storage Shared Preferences SQLite.
Hibernate Annotation 李日貴 (jini) jakarta99 AT gmail.com SoftLeader Tech. Corp. Taiwan Java Annotation Lesson 1.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
SQL Basics Review Reviewing what we’ve learned so far…….
CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
1 Section 1 - Introduction to SQL u SQL is an abbreviation for Structured Query Language. u It is generally pronounced “Sequel” u SQL is a unified language.
Object-Relational Mapping. Contents  Default Mapping Rules  Elementary Mapping  Embeddables  Relationship Mapping  Inheritance Mapping.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
CS6320 – Java Persistence API
Java Persistence Architecture (JPA)
Programming Logic and Design Seventh Edition
STRUCTURED QUERY LANGUAGE
SQL DATA CONSTRAINTS.
JPA: Mapping to an existing database
Topics Persistence API for JAVA EE5 Java Transaction API Entity class.
CS 240 – Advanced Programming Concepts
Presentation transcript:

1 Mapping Persistent Objects Entities represent data in the database, so changes to an entity bean result in changes to the database. That's ultimately the purpose of an entity bean: to provide programmers with a simpler mechanism for accessing and changing data. It is much easier to change a customer's name by calling Customer.setName( ) than by executing an SQL command against the database.

2 Mapping Persistent Objects When a new entity is created and persisted into the entity manager service, a new record must be inserted into the database and a bean instance must be associated with that data. As the entity is used and its state changes, these changes must be synchronized with the data in the database: entries must be inserted, updated, and removed. The process of coordinating the data represented by a bean instance with the database is called persistence.

3 The Customer Bean The Customer bean is a simple entity bean that models the concept of a cruise customer or passenger, but its design and use are applicable across many commercial domains.

4 The Bean Class The Customer bean class is a plain Java object that you map to your relational database. It has fields that hold state and, optionally, it has getter and setter methods to access this state. It must have, at minimum, a no-argument constructor:

5 The Bean Class package com.titan.domain; import public class Customer implements java.io.Serializable { private long id; private long id; private String firstName; private String firstName; private String lastName; private public long getId( ) { return id; } public long getId( ) { return id; } public void setId(long id) { this.id = id; } public void setId(long id) { this.id = id; } public String getFirstName( ) { return firstName; } public String getFirstName( ) { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName( ) { return lastName; } public String getLastName( ) { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public void setLastName(String lastName) { this.lastName = lastName; }

6 The Bean Class Here is the table definition the persistence provider is assuming you are mapping to: create table Customer( id long primary key not null, firstName VARCHAR(255), lastName VARCHAR(255) ); annotation tells the persistence provider that your class can be persisted: Entity { String name( ) default ""; }

7 The Bean Class annotation has one name( ) attribute. This name is used to reference the entity within an EJB QL expression. If you do not provide a value for this attribute, the name defaults to the unqualified name of the bean class. How you apply annotation determines whether you will use the Java bean style for declaring your persistent properties or whether you will use Java fields.

8 The Bean Class If you place annotation on a getter method, as done in this example, then you must apply any other mapping annotations on getter and setter methods in the class. The provider will also assume that any other getter and setter methods in your class represent persistent properties and will automatically map them based on their base name and type.

9 The Bean public class Customer implements java.io.Serializable private long id; private String firstName; private String lastName; public long getId( ) { return id; } public void setId(long id) { this.id = id; } public String getFirstName( ) { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName( ) { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } }

10 The Bean Class Here, we have placed annotation on a member field of the class. The persistence provider will also assume that any other member fields of the class are also persistent properties and will automatically map them based on their base name and type. Any mapping annotations must be placed on member fields in this example, not on getter or setter methods. Here, we are really defining the access type - that is, whether our relational mappings are defined on the fields or the methods of a class.

11 XML Mapping File If you do not want to use annotations to identify and map your entity beans, you can alternatively use an XML mapping file to declare this metadata. By default, the persistence provider will look in the META-INF directory for a file named orm.xml, or you can declare the mapping file in the element in the persistence.xml deployment descriptor. Here's how the Customer entity mapping would look in XML:

12 XML Mapping File The element defines the entity class and access type: PROPERTY or FIELD. Like annotated classes, the persistence provider will assume that any other property in your class is a persistent property, and you do not have to explicitly define them.

13 Basic Relational Mapping A developer can take two directions when implementing entity beans. Some applications start from a Java object model and derive a database schema from this model. Other applications have an existing database schema from which they have to derive a Java object model. If you are creating a database schema from a Java object model, most persistence vendors have tools that can autogenerate database schemas based on the annotations or XML metadata you provide in your code.

14 Basic Relational Mapping If you have an existing database schema, many vendors have tools that can generate Java entity code directly from it. Sometimes, though, this generated code is not very object-oriented and doesn't map to your database very well. Luckily, the Java Persistence specification provides the necessary mapping capabilities to facilitate this problem.

15 Elementary Schema Mappings Here's the table definition in SQL: create table CUSTOMER_TABLE ( CUST_ID integer primary key not null, FIRST_NAME varchar(20) not null lastName varchar(255) not null, ); We want to change the table name and the column names of the id and firstName properties. We want to change the table name and the column names of the id and firstName properties. We also want firstName to have a not-null constraint and want to set the VARCHAR length to 20. We also want firstName to have a not-null constraint and want to set the VARCHAR length to 20.

16 Elementary Schema Mappings Let's modify our original Customer entity class and add the mapping annotations: package com.titan.domain; (name="CUSTOMER_TABLE") public class Customer implements java.io.Serializable { private long id; private String firstName; private String lastName;

17 Elementary nullable=false, columnDefinition="integer") public long getId( ) { return id; } public void setId(long id) { this.id = id; length=20, nullable=false) public String getFirstName( ) { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName( ) { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } }

Let's look at the full definition of this annotation: Let's look at the full definition of this annotation: Table { String name( ) default ""; String name( ) default ""; String catalog( ) default ""; String catalog( ) default ""; String schema( ) default ""; String schema( ) default ""; UniqueConstraint uniqueConstraints( ) default {}; UniqueConstraint uniqueConstraints( ) default {};}

The catalog( ) and schema( ) attributes are self-explanatory, as they identify the relational catalog and schema the table belongs to: UniqueConstraint { String[] columnNames( ); }

20 annotation describes how a particular field or property is mapped to a specific column in a table: Column { String name( ) default ""; boolean unique( ) default false; boolean nullable( ) default true; boolean insertable( ) default true; boolean updatable( ) default true; String columnDefinition( ) default ""; String table( ) default ""; int length( ) default 255; int precision( ) default 0; int scale( ) default 0; }

annotation has the XML equivalent in the element. This element is a subelement of the attribute mapping types,,,, and that are described later in this chapter. <column name="" <column name="" unique="true" unique="true" nullable="true" nullable="true" insertable="true" insertable="true" updatable="true" updatable="true" column-definition="" column-definition="" table="" table="" length="" length="" precision="" precision="" scale="" scale="" /> /></basic>

22 Primary Keys Primary keys can map to one or more properties and must map to one of the following types: any Java primitive type (including wrappers), java.lang.String, or a primary-key class composed of primitives and/or strings. Let's first focus on simple one-property primary keys.

annotation identifies one or more properties that make up the primary key for your table: package Id {} You can generate the primary key for your entity beans manually or have the persistence provider do it for you.

When you want provider-generated keys, you have to use annotation: package GeneratedValue { GenerationType strategy( ) default AUTO; String generator( ) default ""; } public enum GenerationType { TABLE, SEQUENCE, IDENTITY, AUTO }

Persistence providers are required to provide key generation for primitive primary keys. You can define the type of primary generator you would like to have using the strategy( ) attribute. The GeneratorType.AUTO strategy is the most commonly used configuration. The AUTO strategy tells the persistence provider that you are allowing it to generate the key for you. The IDENTITY strategy uses a special column type, available in many database implementations, for creating primary keys.

26 Table Generators The TABLE strategy designates a user-defined relational table from which the numeric keys will be generated. A relational table with the following logical structure is used: create table GENERATOR_TABLE ( PRIMARY_KEY_COLUMN VARCHAR not null, VALUE_COLUMN long not null ); This annotation can be applied to a class or to the method or field of the primary key:

27 Table Generators package METHOD, TableGenerator { String name( ); String table( ) default ""; String catalog( ) default ""; String schema( ) default ""; String pkColumnName( ) default ""; String valueColumnName( ) default ""; String pkColumnValue( ) default ""; int allocationSize( ) default 50; UniqueConstraint[] uniqueConstraints( ) default {}; }

28 Table Generators Let's look at how you would actually use this generator on the Customer entity: package com.titan.domain import public class Customer implements java.io.Serializable { private long id; private String firstName; private String table="GENERATOR_TABLE" pkColumnName="PRIMARY_KEY_COLUMN" valueColumnName="VALUE_COLUMN" pkColumnValue="CUST_ID" allocationSize=10)

29 (strategy=GenerationType.TABLE, generator="CUST_GENERATOR") public long getId( ) { return id; } public void setId(long id) { this.id = id; } public String getFirstName( ) { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName( ) { return lastName; } public void setLastName(String lastName) { this.lastName = lastName;

30 Table Generators Now if you allocate and persist( ) a Customer entity, the id property will be autogenerated when the persist() operation is called. Let's look at how this would be defined within XML: <table-generator name="CUST_GENERATOR" table="GENERATOR_TABLE" pk-column-name="PRIMARY_KEY_COLUMN" value-column-name="VALUE_COLUMN" pk-column-value="CUST_ID" allocation-size="10"/>

31 Sequence Generators Some RDBMs, specifically Oracle, have an efficient, built-in structure to generate IDs sequentially. This is the SEQUENCE generator strategy. This generator type is declared via : package TYPE, SequenceGenerator { String name( ); String sequenceName( ) default ""; int initialValue( ) default 1; int allocationSize( ) default 50; }

32 Sequence Generators Let's again look at applying the SEQUENCE strategy on our Customer entity bean: package com.titan.domain @SequenceGenerator(name="CUSTOMER_SEQUENCE", sequenceName="CUST_SEQ") public class Customer implements java.io.Serializable { private long id; private String firstName; private String lastName;

33 generator="CUSTOMER_SEQUENCE") public long getId( ) { return id; } public void setId(long id) { this.id = id; } public String getFirstName( ) { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName( ) { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } } This example is a little different from our TABLE strategy example in that the generator is declared on the bean's class instead of directly on the property.

34 Sequence Generators TABLE and SEQUENCE generators can be defined in either place. As with the TABLE generation type, the primary key is autogenerated when the EntityManager.persist( ) operation is performed.

35 Sequence Generators Let's look at the XML equivalent for this mapping: <sequence-generator name="CUSTOMER_SEQUENCE" sequence-name="CUST_SEQ" initial-value="0" allocation-size="50"/>

36 Primary-Key Classes and Composite Keys Sometimes relational mappings require a primary key to be composed of multiple persistent properties. For instance, let's say that our relational model specified that our Customer entity should be identified by both its last name and its Social Security number instead of an autogenerated numeric key. These are called composite keys. The Java Persistence specification provides multiple ways to map this type of model. One is through annotation; The other is through annotation.

37 is a class-level annotation and specifies what primary-key class you should use when interacting with the IdClass { Class value( ); } First, let's define our primary-key class:

package com.titan.domain; public class CustomerPK implements java.io.Serializable { private String lastName; private long ssn; public CustomerPK( ) {} public CustomerPK(String lastName, long ssn) { this.lastName = lastName; this.ssn = ssn; } public String getLastName( ) { return this.lastName; } public void setLastName(String lastName) { this.lastName = lastName; }

public long getSsn( ) { return ssn; } public void setSsn(long ssn) { this.ssn = ssn; } public boolean equals(Object obj) { if (obj == this) return true; if (!(obj instanceof CustomerPK)) return false; CustomerPK pk = (CustomerPK)obj; if (!lastName.equals(pk.lastName)) return false; if (ssn != pk.ssn) return false; return true; } public int hashCode( ) { return lastName.hashCode( ) + (int)ssn; }

The primary-key class must meet these requirements: It must be serializable. It must have a public no-arg constructor. It must implement the equals( ) and hashCode( ) methods. Our Customer bean must have the same exact properties as the CustomerPK class, and these properties are annotated with annotations:

package com.titan.domain; public class Customer implements java.io.Serializable { private String firstName; private String lastName; private long ssn; public String getFirstName( ) { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; public String getLastName( ) { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; }

42 public long getSsn( ) { return ssn; } public void setSsn(long ssn) { this.ssn = ssn; } } Let's now look at the XML mapping equivalent com.titan.domain.CustomerPK

A different way to define primary-key classes and composite keys is to embed the primary-key class directly in your bean class. annotation is used for this purpose in conjunction with annotation: package javax.persistence; EmbeddedId { } AttributeOverrides { AttributeOverride[] value( ); }

AttributeOverride { String name( ); Column[] column( ) default {}; } Embeddable { } There are two ways to map the properties of your primary-key class to columns in your table. One is to specify mappings within the primary-key class source code; The other is to

45 Property Mappings Java Persistence has mappings for JDBC Blobs and Clob s, serializable objects, and embeddable objects, as well as optimistic concurrency with version properties. We will discuss all of these.

You may have properties that you don't want to be persistent, and, therefore, the default behavior is inappropriate. This is where annotation comes public class Customer implements java.io.Serializable { private String firstName; private CustomerPK pk; public String getFirstName( ) { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; }

47 public String getLastName( ) { return pk.getLastName( ); public long getSsn( ) { return pk.getSsn( ); public PK getPk( ) { return pk; } public void setPk(CustomerPK pk) { this.pk = pk; } }

Here is what the XML equivalent looks like:

and FetchType annotation is the simplest form of mapping for a persistent property. This is the default mapping type for properties which are primitives, primitive wrapper types, java.lang.String, byte[ ], Byte[ ], char[ ], Character[ ], java.math.BigInteger, java.math.BigDecimal, java.util.Date, java.util.Calendar, java.sql.Date, java.sql.Time, and java.sql.Timestamp. You do not need to tell your persistence manager explicitly that you're mapping a basic property because it can usually figure out how to map it to JDBC using the property's type.

and FetchType Basic { FetchType fetch( ) default EAGER; boolean optional( ) default true; } public enum FetchType { LAZY, EAGER } Let's take our Customer entity and show how to use annotation:

and FetchType package com.titan.domain import public class Customer implements java.io.Serializable { private long id; private String firstName; private public long getId( ) { return id; } public void setId(long id) { this.id = id; optional=false) public String getFirstName( ) { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; }

and FetchType annotation also has an XML equivalent:

Sometimes your persistent properties require a lot of memory. annotation is used to map these large object types. Java Persistence allows you to map some basic types to and have the persistence manager handle them internally as either a Blob or a Clob, depending on the type of the property:

package javax.persistence; Lob { } Properties annotated with are persisted in a: Blob if the Java type is byte[ ], Byte[ ], or java.io.Serializable Clob if the Java type is char[ ], Character[ ], or java.lang.String

annotation maps Java enum types to the database. It is used in conjunction with annotation and lets you specify additional fetch semantics: package javax.persistence; public enum EnumType { ORDINAL, STRING } Enumerated { EnumType value( ) default ORDINAL; }

A Java enum property can be mapped either to the string representation or to the numeric ordinal number of the enum value. For example, let's say we want a Customer entity property that designates the kind of customer that is purchasing a reservation. This could be represented in a Java enum called CustomerType with the enum values UNREGISTERED, REGISTERED, or BIG_SPENDAH. We would do it as follows:

package com.titan.domain; import javax.persistence.*; public enum CustomerType { UNREGISTERED, REGISTERED, BIG_SPENDAH public class Customer implements java.io.Serializable { private long id; private String firstName; private String lastName; private public long getId( ) { return id; } public void setId(long id) { this.id = id;

public String getFirstName( ) { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName( ) { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; (EnumType.STRING) public CustomerType getCustomerType( ) { return customerType; } public void setCustomerType(CustomerType type) { customerType = type; } }

Here's the XML equivalent: STRING

60 Multitable Mappings Sometimes you have to deal with one logical entity that is stored in two different tables. You want one entity bean class to represent your object, but it is mapped into two different tables because you're working with a legacy database model. Java Persistence allows you to map an entity bean class to one or more tables using annotation. For example, let's say our Customer bean has properties that define the address of the Customer, but the address data is stored in a separate table.

61 Multitable Mappings Here's what the tables would look like: create table CUSTOMER_TABLE ( CUST_ID integer Primary Key Not Null, FIRST_NAME varchar(20) not null, LAST_NAME varchar(50) not null ); create table ADDRESS_TABLE ( ADDRESS_ID integer primary key not null, STREET varchar(255) not null, CITY varchar(255) not null, STATE varchar(255) not null );

62 Multitable Mappings To use annotation, the primary key columns of the ADDRESS_TABLE must be joinable with one or more columns in the CUSTOMER_TABLE: SecondaryTable { String name( ); String catalog( ) default ""; String schema( ) default ""; PrimaryKeyJoinColumn[] pkJoinColumns( ) default {}; UniqueConstraint[] uniqueConstraints( ) default {}; } PrimaryKeyJoinColumn { String name( ) default ""; String referencedColumnName( ) default ""; String columnDefinition( ) default ""; }

63 Multitable Mappings The referencedColumnName( ) attribute represents the column name in the CUSTOMER_TABLE that is used to join with the ADDRESS_TABLE. package com.titan.domain; import javax.persistence.*; @SecondaryTable(name="ADDRESS_TABLE", public class Customer implements java.io.Serializable {...

64 Multitable Mappings The next step is to map the street, city, and state properties to columns in the ADDRESS_TABLE. If you remember the annotation, one of the attributes we did not go over fully is the table( ) attribute. You use this to map the address properties to your secondary table: package com.titan.domain; import javax.persistence.*; @SecondaryTable(name="ADDRESS_TABLE",

65 Multitable Mappings public class Customer implements java.io.Serializable { private long id; private String firstName; private String lastName; private String street; private String city; private String table="ADDRESS_TABLE") public String getStreet( ) { return street; } public void setStreet(String street) { this.street = street; table="ADDRESS_TABLE") public String getCity( ) { return city; } public void setCity(String city) { this.city = city; table="ADDRESS_TABLE") public String getState( ) { return state; } public void setState(String state) { this.state = state; }...

66 Multitable Mappings What do you do if you have more than one secondary table? For example, let's say that you want to embed credit card properties, but this information was also stored in another table. In that instance, you would use annotation.