0% found this document useful (0 votes)
3 views26 pages

HIBERNATE

The document provides an overview of Hibernate, focusing on Object-Relational Mapping (ORM) and its various functionalities including CRUD operations, session management, and different mapping strategies such as OneToOne, ManyToOne, and ManyToMany. It includes code examples for setting up Hibernate, configuring session factories, and implementing mappings between entities. Additionally, it discusses advanced topics like eager vs lazy loading and cascading operations.

Uploaded by

Youness Hamdaoui
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views26 pages

HIBERNATE

The document provides an overview of Hibernate, focusing on Object-Relational Mapping (ORM) and its various functionalities including CRUD operations, session management, and different mapping strategies such as OneToOne, ManyToOne, and ManyToMany. It includes code examples for setting up Hibernate, configuring session factories, and implementing mappings between entities. Additionally, it discusses advanced topics like eager vs lazy loading and cascading operations.

Uploaded by

Youness Hamdaoui
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 26

NTIC TECH

2020-2021

abdelhafid el-abbassi
• Intro
• Setting up
• Hibernate CRUD
• Mapping OneToOne
• UNI
• BI
• Mapping ManyToOne OneToMany
• UNI
• BI
• Mapping ManyToMany
• Advanced
• (Eager vs Lazy)
• Cascade

abdelhafid el-abbassi
INTRO
abdelhafid el-abbassi
• Intro
• ORM
• Low-level & minimazes JDBC code

abdelhafid el-abbassi
• ORM (Object-Relationel Mapping)

abdelhafid
THE Id of el-abbassi
the personne
• Retrieving Objects

abdelhafid el-abbassi
• HQL (Hibenate Query Language)

abdelhafid el-abbassi
Setting up
abdelhafid el-abbassi
• https://dev.mysql.com/downloads/connector/j/

abdelhafid el-abbassi
• https://hibernate.org/orm/

abdelhafid el-abbassi
1- Configuration file
abdelhafid el-abbassi
2-Annotation java
abdelhafid el-abbassi
Hibernate CRUD
abdelhafid el-abbassi
Session & SessionFactory
abdelhafid el-abbassi
SessionFactory
SessionFactory is an interface available in org.hibernate
package
• SessionFactory is thread safe so multiple threads can access
the SessionFactory at the same time.
• SessionFactory is Immutable. Once we create SessionFactory
we can not modify it(If you look SessionFactory methods we
don’t have any setter kind of method)
• SessionFactory is created at the time of application startup, it
reads all information from the configuration
file(hibernate.cfg.xml file).
• We should have one SessionFactory for one database
configuration.
abdelhafid el-abbassi
Session In Hibernate.
• Session is an interface available in org.hibernate package
which provides different API to communicate java
application to hibernate.

• The session is not thread-safe.


• The main use of the Session object to perform create, get,
and delete operations for java classes(entity).
• We can have multiple sessions for a SessionFactory.

abdelhafid el-abbassi
1- Mapping the
object
abdelhafid el-abbassi
2-Insert
abdelhafid el-abbassi
3-Read
abdelhafid el-abbassi
4-Update
abdelhafid el-abbassi
5-Delete
abdelhafid el-abbassi
Mapping OneToOne
UNI
BI

abdelhafid el-abbassi
Mapping OneToOne
UNI

@Entity @Entity
public class Personne { public class Voiture {
code @Id
@Id @GeneratedValue(strategy =
@GeneratedValue(strategy = GenerationType.IDENTITY)
GenerationType.IDENTITY) 1..1 private int id;
private int id; @Column
@Column 1..1 private String modele;
private String name; @Column
@Column private Date annee;
private String lastname;

@OneToOne(cascade =
CascadeType.ALL)
@JoinColumn(name = "id_V")
private Voiture voiture;

//code
abdelhafid el-abbassi
Mapping OneToOne
BI

@Entity
@Entity
public class Personne {
public class Voiture {
@Id
@Id
@GeneratedValue(strategy =
@GeneratedValue(strategy =
GenerationType.IDENTITY)
GenerationType.IDENTITY)
1..1 private int id;
private int id;
@Column
@Column
private String name; 1..1 private String modele;
@Column
@Column
private Date annee;
private String lastname;
@OneToOne(mappedBy =
@OneToOne(cascade =
"voiture",cascade =
CascadeType.ALL)
CascadeType.ALL)
@JoinColumn(name = "id_V")
private Personne personne;
private Voiture voiture;

//code
abdelhafid el-abbassi
Mapping ManyToOne
OneToMany
UNI
BI

abdelhafid el-abbassi
ManyToOne OneToMany UNI

@Entity
public class Video { @Entity
@Id public class Commentaire {
@GeneratedValue(strategy = @Id
@GeneratedValue(strategy =
GenerationType.IDENTITY) GenerationType.IDENTITY)
private int id; private int id;

@Column @Column
private String lien; private String lib;
@Column
private String titre; @Column
private String prop;
@OneToMany(cascade =
CascadeType.ALL) //code…
@JoinColumn(name = "id_V")
private List<Commentaire>
commentaires;
abdelhafid el-abbassi

//code…

You might also like