Category Archives: Без рубрики

Java.Hibernate.Beginner.What is lazy loading in Hibernate?

Lazy loading in Hibernate means delaying the retrieval of an associated entity or collection from the database until it’s actually accessed in your code.It helps avoid unnecessary database queries and improves performance by loading only what you need, when you … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Beginner.What is lazy loading in Hibernate?

Java.Hibernate.Beginner.What is a primary key and how do you define it in Hibernate?

You annotate a field or getter in your entity class with @Id. Hibernate maps this to the primary key column in the database. 🔹 Basic example: ✅ Here: The id field is the primary key, defined with @Id. @GeneratedValue(…) tells … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Beginner.What is a primary key and how do you define it in Hibernate?

Java.Hibernate.Beginner.When primary key is composite, lets say from 2 columns how does it look ? give example

✅ When a primary key is composite, it means it consists of two or more columns together forming the unique identifier → no single column is enough to uniquely identify the row, but the combination is. 🔹 How does a … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Beginner.When primary key is composite, lets say from 2 columns how does it look ? give example

Java.Hibernate.Beginner.Why do we need primary key ?

🔹 1) Uniqueness guarantee A primary key enforces uniqueness → ensures every row has a unique identifier → no duplicates allowed in primary key columns. 🔹 2) Non-nullability A primary key cannot be NULL → every row must have a … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Beginner.Why do we need primary key ?

Java.Hibernate.Beginner.How do you implement a composite key in Hibernate?

A composite key means the primary key of a table is made up of two or more columns, and you need to map this combined key in your entity.In Hibernate (and JPA), you implement composite keys using either: @Embeddable + … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Beginner.How do you implement a composite key in Hibernate?

Java.Hibernate.Beginner.What is many-to-many mapping in Hibernate?

A many-to-many mapping models a relationship where multiple instances of one entity can relate to multiple instances of another entity, and vice versa — like a student can enroll in many courses, and a course can have many students. In … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Beginner.What is many-to-many mapping in Hibernate?

Java.Hibernate.Beginner.When i need @OneToMany without mappedBy ?

You use @OneToMany without mappedBy when you want to create a unidirectional one-to-many relationship where only the parent knows about the children, and you don’t want or can’t add a foreign key to the child table. 🔹 What happens technically? … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Beginner.When i need @OneToMany without mappedBy ?

Java.Hibernate.Beginner.Explain mappedBy and joinTables?

🔹 By default in JPA/Hibernate: If you write @OneToMany without mappedBy, Hibernate creates a join table to associate the two entities. A join table is a separate table just to link parent IDs and child IDs → unnecessary if you … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Beginner.Explain mappedBy and joinTables?

Java.Hibernate.Beginner.What is one-to-many mapping in Hibernate?

A one-to-many mapping models a relationship where one entity instance is associated with many instances of another entity. This is the typical way to map hierarchical or parent-child relationships in a relational database and your Java entity model. 🔹 Example … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Beginner.What is one-to-many mapping in Hibernate?

Java.Hibernate.Beginner.What does ibidirectional look like in data base and when i get profile.getUser(), is there any additional sql generated ?

✅ 1) What does a one-to-one relationship look like in the database? There’s one table for each entity, e.g.: users table with primary key id. user_profile table with primary key id and a foreign key column pointing back to users.id. … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Beginner.What does ibidirectional look like in data base and when i get profile.getUser(), is there any additional sql generated ?