SlideShare a Scribd company logo
1 of 23
mustafa daşgın mdasgin.blogspot.com mustafa.dasgin@prime.com.tr JPA
Kalıcı olarak barındırılan veri İlişkisel veri tabanı, dosya, vb. Veri bütünlüğü, güvenlik, eş zamanlı erişim vb. kriterlerin sağlanması Persistence Nedir?
Birbirleriyle ilişkili nesnelerin kaydedilip daha sonra tekrar aynı şekilde oluşturulması Java’da nesneler – VT’de tablolar Granülarite Uyumsuzluğu Subtype Uyumsuzluğu Identity Uyumsuzluğu İlişkisel Uyumsuzluklar Veriye Erişim Uyumsuzlukları Java Nesnelerinde Kalıcılık
Granülarite Uyumsuzluğu public class User { private String username; private String name; private Adressaddress; private Set billingDetails; // getter/setter... } public class BillingDetails { private String accountNumber; private String accountName; private User user; // getter/setter... } public class Adress { private String street; private String city; }
Granülarite Uyumsuzluğu (Devam) create table USERS ( USERNAME varchar(15) not null primary key, NAME varchar(50) not null, ADDRESS_STREET varchar(50), ADDRESS_CITY varchar(15), ) create table BILLING_DETAILS ( ACCOUNT_NUMBER varchar(10) not null primary key, ACCOUNT_NAME varchar(50) not null, USERNAME varchar(15) foreign key references user )
Inheritance ve Polymorphism gerçekleştirimi Hepsi tek tabloda Her biri ayrı tabloda Ortak değişkenler tek tabloda vb. Subtype Uyumsuzluğu
Java’da iki nesne eşitliği: a ==b  a.equals(b)  VT’de eşitlik Primary Key Önerilen her nesnenin primary key için “id” değişkeni olmalı Identity Uyumsuzluğu
Nesne ilişkileri yönlüdür (iki yönlü olabilir) : Many-to-many ilişkiler olabilir VT’de ilişki foreign key ile sağlanır Tablolar arası ilişki her zaman one-to-one  ya da one-to-many Many-to-many ilişkilerde üçüncü bir tablo gerekli İlişkisel Uyumsuzluklar public class User { private Set billingDetails; ... } public class BillingDetails { private User user; 	// private Set user; }
Nesne veri erişimi VT’de erişim Veriye Erişim Uyumsuzlukları aUser.getBillingDetails().getAccountNumber() select * from USERS u left outer join BILLING_DETAILS bd on bd.USER_ID = u.USER_ID where u.USER_ID = 123
Kalıcı veri üzerinde değişiklik yapabilmek için select (tablo ve kolon isimleri) insert (tablo ve kolon isimleri) update (tablo ve kolon isimleri) 	komutları Java kodları içerisinde yazılmalı. (Her bir nesne için) Diğer Bir Problem - JDBC
Object/Relational Mapping Nesneler ve VT arasında eşleşmenin, tanımlanan metadata bilgileri ile otomatik gerçekleştirilmesi Bir gösterimden diğerine dönüşüm işlemi  (Nesne <-> VT) ORM Nedir?
Temel CRUD işlemini gerçekleştirebilmek için API Sınıf ve nitelikleri tasvir eden SQL benzeri sorgu dili Eşleme için metadata tanımlama yöntemi Transaction, Concurrency, Caching, Lazy-loading, vb. özellikler  ORM Çöz. Sunması Gerekenler
EJB 3.0 ile tanımlanan Persistence API belirtimi Hibernate geliştiricileri JPA belirtiminin oluşturulmasında katkı sağladı. Hibernate Modülleri Hibernate Core (Varolan Hibernate yetenekleri) Hibernate Annotation Hibernate EntityManager (JPA belirtimi için Hibernate yeteneklerinin bir kısmının sarmalanmış hali) JPA Nedir? Hibernate Nedir?
Temel Annotation Mapping @Entity @Table(name=“User”) public class User { @Id @GeneratedValue(strategy = GenerationType.AUTO) 	@Column(name=“user_id”) private Long id; 	@Column(name=“user_name”, nullable = false) private String name; 	@Column(name=“user_surname”, nullable = false) private String surname; ...
@Embeddable / @Embedded @Embeddable public class Address { @Column(name = "ADDRESS_STREET", nullable = false) private String street; @Column(name = "ADDRESS_ZIPCODE", nullable = false) private String zipcode; @Column(name = "ADDRESS_CITY", nullable = false) private String city; ... } @Entity @Table(name = "USERS") public class User { ... @Embedded private Address homeAddress; ... }
@Embedded @AttributeOverrides @Entity @Table(name = "USERS") public class User { ... @Embedded @AttributeOverrides( { @AttributeOverride(name = "street", column = @Column(name="HOME_STREET") ), @AttributeOverride(name = "zipcode", column = @Column(name="HOME_ZIPCODE") ), @AttributeOverride(name = "city", column = @Column(name="HOME_CITY") ) }) private Address homeAddress; ... }
@MappedSuperClass (Kalıtım) @MappedSuperclass public abstract class BillingDetails { @Column(name = "OWNER", nullable = false) private String owner; ... }
@MappedSuperClass (Devam) @Entity @AttributeOverride(name = "owner", column = @Column(name = "CC_OWNER", nullable = false) ) public class CreditCard extends BillingDetails { @Id @GeneratedValue @Column(name = "CREDIT_CARD_ID") private Long id = null; @Column(name = "NUMBER", nullable = false) private String number; ... }
@Inheritance @Entity @Inheritance(strategy = InheritanceType.JOINED) public abstract class BillingDetails { @Id @GeneratedValue @Column(name = "BILLING_DETAILS_ID") private Long id = null; ... } @Entity @PrimaryKeyJoinColumn(name = "CREDIT_CARD_ID") public class CreditCard { ... }
@ManyToOne / @OneToMany public class Phone{ ... @ManyToOne @JoinColumn(name = “USER_ID", nullable = false) private Useruser; ... } public class User{ ... @OneToMany(mappedBy = “user") private Set<Phone> phones= new HashSet<Phone>(); ... }
@OneToOne public class User { ... @OneToOne @JoinColumn(name="SHIPPING_ADDRESS_ID") private Address shippingAddress; ... } public class Address { ... @OneToOne(mappedBy = "shippingAddress") private User user; ... }
@ManyToMany @ManyToMany @JoinTable(name = "CATEGORY_ITEM", joinColumns= {@JoinColumn(name = "CATEGORY_ID")}, inverseJoinColumns= {@JoinColumn(name = "ITEM_ID")}) private Set<Item> items = new HashSet<Item>(); @ManyToMany(mappedBy = "items") private Set<Category> categories = new HashSet<Category>();
Java Persistence with Hibernate (Manning) Kaynak

More Related Content

Featured

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Featured (20)

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 

Jpa

  • 1. mustafa daşgın mdasgin.blogspot.com mustafa.dasgin@prime.com.tr JPA
  • 2. Kalıcı olarak barındırılan veri İlişkisel veri tabanı, dosya, vb. Veri bütünlüğü, güvenlik, eş zamanlı erişim vb. kriterlerin sağlanması Persistence Nedir?
  • 3. Birbirleriyle ilişkili nesnelerin kaydedilip daha sonra tekrar aynı şekilde oluşturulması Java’da nesneler – VT’de tablolar Granülarite Uyumsuzluğu Subtype Uyumsuzluğu Identity Uyumsuzluğu İlişkisel Uyumsuzluklar Veriye Erişim Uyumsuzlukları Java Nesnelerinde Kalıcılık
  • 4. Granülarite Uyumsuzluğu public class User { private String username; private String name; private Adressaddress; private Set billingDetails; // getter/setter... } public class BillingDetails { private String accountNumber; private String accountName; private User user; // getter/setter... } public class Adress { private String street; private String city; }
  • 5. Granülarite Uyumsuzluğu (Devam) create table USERS ( USERNAME varchar(15) not null primary key, NAME varchar(50) not null, ADDRESS_STREET varchar(50), ADDRESS_CITY varchar(15), ) create table BILLING_DETAILS ( ACCOUNT_NUMBER varchar(10) not null primary key, ACCOUNT_NAME varchar(50) not null, USERNAME varchar(15) foreign key references user )
  • 6. Inheritance ve Polymorphism gerçekleştirimi Hepsi tek tabloda Her biri ayrı tabloda Ortak değişkenler tek tabloda vb. Subtype Uyumsuzluğu
  • 7. Java’da iki nesne eşitliği: a ==b a.equals(b) VT’de eşitlik Primary Key Önerilen her nesnenin primary key için “id” değişkeni olmalı Identity Uyumsuzluğu
  • 8. Nesne ilişkileri yönlüdür (iki yönlü olabilir) : Many-to-many ilişkiler olabilir VT’de ilişki foreign key ile sağlanır Tablolar arası ilişki her zaman one-to-one ya da one-to-many Many-to-many ilişkilerde üçüncü bir tablo gerekli İlişkisel Uyumsuzluklar public class User { private Set billingDetails; ... } public class BillingDetails { private User user; // private Set user; }
  • 9. Nesne veri erişimi VT’de erişim Veriye Erişim Uyumsuzlukları aUser.getBillingDetails().getAccountNumber() select * from USERS u left outer join BILLING_DETAILS bd on bd.USER_ID = u.USER_ID where u.USER_ID = 123
  • 10. Kalıcı veri üzerinde değişiklik yapabilmek için select (tablo ve kolon isimleri) insert (tablo ve kolon isimleri) update (tablo ve kolon isimleri) komutları Java kodları içerisinde yazılmalı. (Her bir nesne için) Diğer Bir Problem - JDBC
  • 11. Object/Relational Mapping Nesneler ve VT arasında eşleşmenin, tanımlanan metadata bilgileri ile otomatik gerçekleştirilmesi Bir gösterimden diğerine dönüşüm işlemi (Nesne <-> VT) ORM Nedir?
  • 12. Temel CRUD işlemini gerçekleştirebilmek için API Sınıf ve nitelikleri tasvir eden SQL benzeri sorgu dili Eşleme için metadata tanımlama yöntemi Transaction, Concurrency, Caching, Lazy-loading, vb. özellikler ORM Çöz. Sunması Gerekenler
  • 13. EJB 3.0 ile tanımlanan Persistence API belirtimi Hibernate geliştiricileri JPA belirtiminin oluşturulmasında katkı sağladı. Hibernate Modülleri Hibernate Core (Varolan Hibernate yetenekleri) Hibernate Annotation Hibernate EntityManager (JPA belirtimi için Hibernate yeteneklerinin bir kısmının sarmalanmış hali) JPA Nedir? Hibernate Nedir?
  • 14. Temel Annotation Mapping @Entity @Table(name=“User”) public class User { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name=“user_id”) private Long id; @Column(name=“user_name”, nullable = false) private String name; @Column(name=“user_surname”, nullable = false) private String surname; ...
  • 15. @Embeddable / @Embedded @Embeddable public class Address { @Column(name = "ADDRESS_STREET", nullable = false) private String street; @Column(name = "ADDRESS_ZIPCODE", nullable = false) private String zipcode; @Column(name = "ADDRESS_CITY", nullable = false) private String city; ... } @Entity @Table(name = "USERS") public class User { ... @Embedded private Address homeAddress; ... }
  • 16. @Embedded @AttributeOverrides @Entity @Table(name = "USERS") public class User { ... @Embedded @AttributeOverrides( { @AttributeOverride(name = "street", column = @Column(name="HOME_STREET") ), @AttributeOverride(name = "zipcode", column = @Column(name="HOME_ZIPCODE") ), @AttributeOverride(name = "city", column = @Column(name="HOME_CITY") ) }) private Address homeAddress; ... }
  • 17. @MappedSuperClass (Kalıtım) @MappedSuperclass public abstract class BillingDetails { @Column(name = "OWNER", nullable = false) private String owner; ... }
  • 18. @MappedSuperClass (Devam) @Entity @AttributeOverride(name = "owner", column = @Column(name = "CC_OWNER", nullable = false) ) public class CreditCard extends BillingDetails { @Id @GeneratedValue @Column(name = "CREDIT_CARD_ID") private Long id = null; @Column(name = "NUMBER", nullable = false) private String number; ... }
  • 19. @Inheritance @Entity @Inheritance(strategy = InheritanceType.JOINED) public abstract class BillingDetails { @Id @GeneratedValue @Column(name = "BILLING_DETAILS_ID") private Long id = null; ... } @Entity @PrimaryKeyJoinColumn(name = "CREDIT_CARD_ID") public class CreditCard { ... }
  • 20. @ManyToOne / @OneToMany public class Phone{ ... @ManyToOne @JoinColumn(name = “USER_ID", nullable = false) private Useruser; ... } public class User{ ... @OneToMany(mappedBy = “user") private Set<Phone> phones= new HashSet<Phone>(); ... }
  • 21. @OneToOne public class User { ... @OneToOne @JoinColumn(name="SHIPPING_ADDRESS_ID") private Address shippingAddress; ... } public class Address { ... @OneToOne(mappedBy = "shippingAddress") private User user; ... }
  • 22. @ManyToMany @ManyToMany @JoinTable(name = "CATEGORY_ITEM", joinColumns= {@JoinColumn(name = "CATEGORY_ID")}, inverseJoinColumns= {@JoinColumn(name = "ITEM_ID")}) private Set<Item> items = new HashSet<Item>(); @ManyToMany(mappedBy = "items") private Set<Category> categories = new HashSet<Category>();
  • 23. Java Persistence with Hibernate (Manning) Kaynak