orm
TRANSCRIPT
Internet Programming IIYildiz Technical University 2015
Object Relational Mapping
Ömer Taşkın
OUTLINE
• What is ORM?
• Most known ORM Tools
• JPA & Hibernate
IP II - ORM 2
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
ORM Tools
IP II - ORM 4
• .net - nHibernate
• .net – Ado.net Entity Framework
• Java – Hibernate
• Java – EclipseLink
• Java – TopLink
• PHP – Doctrine
• Python – Django
…
…
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
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;
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;
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
}