orm
TRANSCRIPT
![Page 1: Orm](https://reader036.vdocument.in/reader036/viewer/2022080214/55a964251a28ab45108b465e/html5/thumbnails/1.jpg)
Internet Programming IIYildiz Technical University 2015
Object Relational Mapping
Ömer Taşkın
![Page 2: Orm](https://reader036.vdocument.in/reader036/viewer/2022080214/55a964251a28ab45108b465e/html5/thumbnails/2.jpg)
OUTLINE
• What is ORM?
• Most known ORM Tools
• JPA & Hibernate
IP II - ORM 2
![Page 3: Orm](https://reader036.vdocument.in/reader036/viewer/2022080214/55a964251a28ab45108b465e/html5/thumbnails/3.jpg)
What is ORM?
IP II - ORM 3
• Provides to mapping Objects to DB tables and vice versa
• Generates and runs SQL queries
• Avoids SQL Injections
![Page 4: Orm](https://reader036.vdocument.in/reader036/viewer/2022080214/55a964251a28ab45108b465e/html5/thumbnails/4.jpg)
ORM Tools
IP II - ORM 4
• .net - nHibernate
• .net – Ado.net Entity Framework
• Java – Hibernate
• Java – EclipseLink
• Java – TopLink
• PHP – Doctrine
• Python – Django
…
…
![Page 5: Orm](https://reader036.vdocument.in/reader036/viewer/2022080214/55a964251a28ab45108b465e/html5/thumbnails/5.jpg)
Jpa & Hibernate
IP II - ORM 5
• JPA is orm standard of Java
• Hibernate is one of most used Java Orm framework
• allows writing hql queries like SQL
• has Criteria API
![Page 6: Orm](https://reader036.vdocument.in/reader036/viewer/2022080214/55a964251a28ab45108b465e/html5/thumbnails/6.jpg)
Jpa & Hibernate
IP II - ORM 6
@Entity annotation declares a class as an entity.
@Table annotation is used to declare tablename and schema
@Id annotation lets you define which property is the identifier (PRIMARY KEY) of
your entity
@Column annotation declares field name
@Table(name = “customer”)
@Id
@Column(“CUSTOMER_ID”)
private Integer customerId;
![Page 7: Orm](https://reader036.vdocument.in/reader036/viewer/2022080214/55a964251a28ab45108b465e/html5/thumbnails/7.jpg)
Jpa & Hibernate - Join
IP II - ORM 7
@OneToOne annotation is used for 1-1 mapping
@OneToMany annotation is used for 1-n mapping
@ManyToOne annotation is used for n-1 mapping
@ManyToMany annotation is used for n-n mapping
@JoinColumn annotation declares which column would be join field
@ManyToOne
@JoinField(“MEMBER_ID”)
private Member member;
![Page 8: Orm](https://reader036.vdocument.in/reader036/viewer/2022080214/55a964251a28ab45108b465e/html5/thumbnails/8.jpg)
Jpa & Hibernate – Fully mapped example
IP II - ORM 8
@Entity
@Table
public class Customer {
@Id
@GeneratedValue
@Column(name = “CUSTOMER_ID”)
private Integer customerId;
@Column(name = “CUSTOMER_NAME”)
private String customerName;
// getter & setters
}