Author Archives: Stanislav_Panteleev

Java.Hibernate.Medium.How do you configure Hibernate with Spring (e.g., LocalSessionFactoryBean)?

✅ Short Answer In a traditional Spring (non-Spring Boot) app, you configure Hibernate using LocalSessionFactoryBean to create the Hibernate SessionFactory, set up a DataSource, and configure a HibernateTransactionManager for declarative transactions. 🔎 Detailed Explanation Here’s a typical setup in a … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Medium.How do you configure Hibernate with Spring (e.g., LocalSessionFactoryBean)?

Java.Hibernate.Medium.What are the differences between JPA and native Hibernate APIs?

✅ Short Answer JPA API is the standardized Java API for persistence, defined by the Jakarta Persistence specification → it’s portable across providers (Hibernate, EclipseLink, OpenJPA, etc.). Hibernate native API gives you Hibernate-specific features beyond JPA → more flexibility, but … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Medium.What are the differences between JPA and native Hibernate APIs?

Java.Hibernate.Medium.When do i need such type conversion ?

✅ Short Answer You need custom type conversion when you want to map Java types that don’t directly match database column types, or when you need to store complex or non-standard values — beyond what JPA handles automatically. 🔎 Detailed … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Medium.When do i need such type conversion ?

Java.Hibernate.Medium.What are user-defined types and how do you implement them?

✅ Short Answer In Hibernate, user-defined types let you customize how your Java objects are mapped to database columns by implementing the UserType (or the newer BasicType/AttributeConverter in JPA).They’re useful when you need to map non-standard data types (like custom … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Medium.What are user-defined types and how do you implement them?

Java.Hibernate.Middle.How do you map enums in Hibernate?

✅ Short Answer In JPA/Hibernate, you map enums with the @Enumerated annotation, specifying whether to persist them as ordinal values (integers) or string names. 🔎 Detailed Explanation 🔹 Basic mapping example 🔹 EnumType options✅ EnumType.ORDINAL (default): Stores enum’s zero-based ordinal … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Middle.How do you map enums in Hibernate?

Java.Hibernate.Middle.What is the @Version annotation for?

🔎 Detailed Explanation 🔹 How it works When you annotate a field with @Version, Hibernate automatically:✅ Reads the version value when loading the entity.✅ Checks the version when updating → if the version in the database doesn’t match the version … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Middle.What is the @Version annotation for?

Java.Hibernate.Medium.Can i load number of records with naturalId ?

✅ Short Answer No — Hibernate’s natural ID API (session.byNaturalId(…)) is designed for one entity lookup at a time.It doesn’t support batch fetching multiple different natural IDs in a single call. 🔎 Detailed Explanation 🔹 How natural ID API works … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Medium.Can i load number of records with naturalId ?

Java.Hibernate.Medium.What is @NaturalId and how is it used?

✅ Short Answer The @NaturalId annotation marks a field as a natural business key → a unique, immutable identifier other than the primary key.Hibernate allows you to load entities efficiently by natural IDs, caching them separately from the primary key. … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Medium.What is @NaturalId and how is it used?

Java.Hibernate.Medium.What does the @Formula annotation do?

✅ Short Answer The @Formula annotation lets you map a read-only calculated property in an entity by defining a SQL expression → Hibernate includes it in the SELECT statement when loading the entity. 🔎 Detailed Explanation 🔹 @Formula allows you … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Medium.What does the @Formula annotation do?

Java.Hibernate.Middle.What will happen if i will not write @JoinColumn on the owning side ?

✅ Short Answer If you don’t specify @JoinColumn on the owning side (usually the @ManyToOne side), JPA will still create a foreign key column, but it will use a default naming convention → typically <entity_field>_id.This can lead to unexpected or … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Middle.What will happen if i will not write @JoinColumn on the owning side ?