970 likes | 1.2k Views
v110223. Java Persistence: Core ORM. 2. Goals. Be able to map a single class and properties to the database using class annotations and ORM descriptorsBe able to get and set properties using get/set API calls instead of SQL. v110223. Java Persistence: Core ORM. 3. Objectives. Entitiesclass annotat
E N D
1. v110223 Java Persistence: Core ORM 1 Java Persistence:Core Object/RelationalMapping
2. v110223 Java Persistence: Core ORM 2 Goals Be able to map a single class and properties to the database using class annotations and ORM descriptors
Be able to get and set properties using get/set API calls instead of SQL
3. v110223 Java Persistence: Core ORM 3 Objectives Entities
class annotations
orm.xml descriptor
Primary Key Generation
Primary Keys
simple
composite
Fine Tuning Objects
Multi-table Mappings
Secondary Tables
Embedded Objects
4. v110223 Java Persistence: Core ORM 4 Entities Plain Old Java Object (POJO) Classes
Instantiated and used just like any other POJO
Bike bike = new Bike(1);
bike.setMake("trek");
bike.setModel("2200");
bike.setSize(26);
Mapped to the database schema
Interact with EntityManager to perform persistence operations
em.persist(bike);
Bike bike2 = em.find(Bike.class, 1);
em.remove(bike2);
Must
have a no-arg constructor (spec says non-private; hibernate can work with private)
be denoted as an Entity (either within class or descriptor)
have at least 1 field/property labeled as Id
5. v110223 Java Persistence: Core ORM 5 Annotated Entity Example: Bike.java