dev-resources.site
for different kinds of informations.
Hibernate Cheat Sheet
Published at
11/12/2023
Categories
java
webdev
hibernate
springboot
Author
burakboduroglu
Author
14 person written this
burakboduroglu
open
## 📃 JPA Hibernate Annotations
@Entity :
- This annotation is used to mark a class as an entity class.
- This annotation is used to create a table in the database.
@Entity
public class Brand {
}
@Table :
- @Table annotation is used to specify the details of the table that will be created in the database.
- The name attribute of the @Table annotation is used to specify the name of the table.
@Entity
@Table(name = "brands")
public class Brand {
}
@Column :
- @Column annotation is used to specify the details of the column that will be created in the database.
- The name attribute of the @Column annotation is used to specify the name of the column.
@Entity
@Table(name = "brands")
public class Brand {
@Column(name = "brandName")
private String brandName;
}
@id :
- @id annotation is used to specify the primary key of an entity.
- The @id annotation is always used with the @GeneratedValue annotation.
@Entity
@Table(name = "brands")
public class Brand {
@Id
@Column(name = "id")
private int id;
}
@ManyToOne :
- @ManyToOne annotation is used to specify many to one relationship with another entity.
@Entity
@Table(name = "brands")
public class Brand {
@ManyToOne
@JoinColumn(name = "brandsDetails")
private BrandDetail brandDetail;
}
@OneToMany :
- @OneToMany annotation is used to specify one to many relationship with another entity.
- The mappedBy attribute of the @OneToMany annotation is used to specify the property of the entity that is the owner of the relationship.
@Entity
@Table(name = "brands")
public class Brand {
@OneToMany(mappedBy = "brands", fetch = FetchType.EAGER)
private BrandDetail brandDetail;
}
@PrimaryKeyJoinColumn :
- @PrimaryKeyJoinColumn annotation is used to specify the primary key of the entity that is the owner of the relationship.
@Entity
@Table(name = "brands")
public class Brand {
@PrimaryKeyJoinColumn
private int id;
}
@JoinColumn :
- @JoinColumn annotation is used to specify the column that will be created in the database as a foreign key.
@Entity
@Table(name = "brands")
public class Brand {
@JoinColumn(name = "brandDetail")
private BrandDetail brandDetail;
}
@JoinTable ve @MapsId:
- It is used to specify the join table that will be created in the database.
- @JoinTable annotation is used to specify the join table that will be created in the database.
- @MapsId annotation is used to specify the primary key of the entity that is the owner of the relationship.
@Entity
@Table(name = "brands")
public class Brand {
@JoinTable(name = "brands")
private BrandDetail brandDetail;
}
@OneToOne:
- @OneToOne annotation is used to specify one to one relationship with another entity.
- The mappedBy attribute of the @OneToOne annotation is used to specify the property of the entity that is the owner of the relationship.
@Entity
@Table(name = "brands")
public class Brand {
@OneToOne(mappedBy = "brands")
private BrandDetail brandDetail;
}
✅ If you like this article, you can give me a like on. 😎
Thanks for reading. 🙏
hibernate Article's
30 articles in total
JOOQ Is Not a Replacement for Hibernate. They Solve Different Problems
read article
Persistence Context в Hibernate Zoo: путешествие объекта по жизненным состояниям
read article
Unidirectional associations for one-to-many
read article
Como eu reduzi em até 99% o tempo de resposta da minha API
read article
Hibernate Zoo: Жадный Гиппопотам и Ленивый Лемур (Lazy vs Eager)
read article
🐾 Hibernate Zoo: Путеводитель по языкам запросов в мире данных 🐾
read article
How To Fetch Data By Using DTO Projection In Spring Data JPA
read article
Ubuntu 22.04 Hibernate Using Swap File
read article
Зоопарк Hibernate: N+1 запросов или как накормить жадного бегемота
read article
Spring Data JPA Stream Query Methods
read article
Uma breve introdução ao Hibernate
read article
Ubuntu hibernate
read article
Eager vs Lazy Initialization of Spring Beans
read article
Understanding JPA Mappings in Spring Boot: One-to-One, One-to-Many, Many-to-One, and Many-to-Many Relationships
read article
Java Hibernate vs JPA: Rapid review for you
read article
Hibernate Connection Library with GUI Generation
read article
what is JPA? explain few configurations
read article
Demystifying Hibernate: A Beginner's Journey
read article
How to deal with N+1 problems with Hibernate
read article
Java Hibernate vs JPA: Quick Review
read article
Uppercase table names in Spring Boot
read article
Hiring Alert - Java Developer- Blockchain
read article
H2 database Setup Error Unable to load name org.hibernate.dialect.Oracle10gDialect
read article
Capitalisation of table name generated by Hibernate when using MySQL server
read article
Display SQL statement generated by Hibernate JPA in Spring Boot environment
read article
Advanced and dynamic searching with Spring Data JPA
read article
Defining JPA/Hibernate Entities in Kotlin
read article
Criteria Queries and JPA Metamodel with Spring Boot and Kotlin
read article
How to save Hibernate Entity changes to Database
read article
Hibernate Cheat Sheet
currently reading
Featured ones: