Содержание
- 2. Basics A foreign key can be one or more columns that reference a unique key, usually
- 3. Multiplicity in Entity Relationships Multiplicities are of the following types: Many-to-one: Multiple instances of an entity
- 4. CM Database Schema * Victor Mozharsky
- 5. Many-to-One Mappings A many-to-one mapping is defined by annotating the attribute in the source entity (the
- 6. Exercise: Read a Payment Create a project for read payment data by payment id with a
- 7. CM Database Schema * Victor Mozharsky
- 8. Payment Entity (1 of 2) @Entity public class Payment { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) private int id; private
- 9. Payment Entity (2 of 2) public Merchant getMerchant(){ return merchant; } public void setMerchant(Merchant value){ merchant
- 10. DAO & Service Interfaces public interface PaymentDao { public List findByMerchantId(int id); public double getPaymentSum(); public
- 11. PaymentDaoImpl Class public Payment findById(int id){ return em.find(Payment.class, id); } * Victor Mozharsky
- 12. Main Class @SuppressWarnings("resource") public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml"); PaymentService paymentService
- 13. Exercise: Read a Payment See P351ReadPayment project for the full text * Victor Mozharsky
- 14. Exercise: Group Payments Modify P237Grouping project using entities from the previous project * Victor Mozharsky
- 15. PaymentDaoImp Class public List getTotalReport(){ String txt = "SELECT new com.bionic.edu.Result (p.merchant.name, count(p), SUM(p.chargePayed))"; txt +=
- 16. Main Class @SuppressWarnings("resource") public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml"); PaymentService paymentService
- 17. Exercise: Group Payments See P352GroupPayment project for the full text * Victor Mozharsky
- 18. One-to-Many Mappings An entity instance can be related to multiple instances of the other entities One-to-many
- 19. Exercise: Read a Merchant’s Payments Create a project for read payment data that correspond to a
- 20. CM Database Schema * Victor Mozharsky
- 21. Merchant Entity @Entity public class Merchant { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) private int id; private String name; private
- 22. Main Class (1 of 2) @SuppressWarnings("resource") public static void main(String[] args) { ApplicationContext context = new
- 23. Main Class (2 of 2) System.out.println(" "); Collection payments = m.getPayments(); for (Payment p : payments)
- 24. Exercise: Read a Merchant’s Payments See P353MerchantPayments project for the full text * Victor Mozharsky
- 25. Many-to-Many Mappings The entity instances can be related to multiple instances of each other Many-to-many relationships
- 26. @JoinTable Annotation @JoinTable(name=“table name”, joinColumns=@JoinColumn(name=“c1Id”), inverseJoinColumns= @JoinColumn(name=“c2Id”)) * Victor Mozharsky
- 27. Exercise: Read Customer’s Merchants Create a project to read data about merchants whose goods were bought
- 28. Customer Entity (1 of 2) @Entity public class Customer { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) private int id; private
- 29. Customer Entity (2 of 2) @ManyToMany @JoinTable(name="Payment", joinColumns=@JoinColumn(name="customerId"), inverseJoinColumns=@JoinColumn(name="merchantId")) private Collection merchants; * Victor Mozharsky
- 30. Main Class @SuppressWarnings("resource") public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml"); CustomerService customerService
- 31. Exercise: Read Customer’s Merchants See P354CustAndMerch project for the full text * Victor Mozharsky
- 32. Lazy Relationships The fetch mode can be specified on any of the four relationship mapping types:
- 33. One-to-One Mappings Each entity instance is related to a single instance of another entity One-to-one relationships
- 34. Embedded Objects (1 of 2) An embedded object is one that is dependent on an entity
- 35. Embedded Objects (2 of 2) We can share the same embedded object type with other entities
- 36. Embedded Type An embedded type is marked as such by adding the @Embeddable annotation to the
- 37. Address Embedded Type @Embeddable @Access(AccessType.FIELD) public class Address { private String street; private String city; private
- 38. Using an Embedded Object @Entity public class Employee { @Id private int id; private String name;
- 39. Reuse of Embedded Type An Address class could be reused in both Employee and Company entities
- 40. Database Schema Generation Automatically generation the tables and database schema for a persistence unit can be
- 41. eclipselink.ddl-generation Values create-tables – if the table already exists then it will not be dropped or
- 42. Schema Generation Practice One of the complaints around schema generation is that you can’t specify everything
- 44. Скачать презентацию