Questions tagged [hibernate]

Hibernate is an object-relational mapping (ORM) library for the Java language enabling developers to utilize POJO-style domain models in their applications in ways extending well beyond Object/Relational Mapping.

Hibernate is the umbrella for a collection of , most notably Hibernate ORM which provides Object/Relational Mapping for domain objects.
In addition to its own "native" API, Hibernate ORM is also an implementation of the Java Persistence API () specification.

Related tags

Beginner's resources

Frequently asked questions

People often ask the following questions:

94278 questions
194
votes
14 answers

What is lazy loading in Hibernate?

What is lazy loading in Java? I don't understand the process. Can anybody help me to understand the process of lazy loading?
rocker
  • 11,317
  • 7
  • 22
  • 12
193
votes
8 answers

Difference between @OneToMany and @ElementCollection?

What is the difference between using a @OneToMany and @ElementCollection annotation since both work on the one-to-many relationship?
n_g
  • 3,315
  • 8
  • 25
  • 29
193
votes
17 answers

How to fix Hibernate LazyInitializationException: failed to lazily initialize a collection of roles, could not initialize proxy - no Session

In the custom AuthenticationProvider from my spring project, I am trying read the list of authorities of the logged user, but I am facing the following error: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of…
Kleber Mota
  • 8,521
  • 31
  • 94
  • 188
191
votes
5 answers

In which case do you use the JPA @JoinTable annotation?

In which case do you use the JPA @JoinTable annotation?
kostas trichas
  • 2,923
  • 7
  • 28
  • 37
189
votes
13 answers

Disable all Database related auto configuration in Spring Boot

I am using Spring Boot to develop two applications, one serves as the server and other one is a client app. However, both of them are the same app that function differently based on the active profile. I am using auto configuration feature of Spring…
yuva
  • 3,108
  • 4
  • 20
  • 35
188
votes
10 answers

How to convert a Hibernate proxy to a real entity object

During a Hibernate Session, I am loading some objects and some of them are loaded as proxies due to lazy loading. It's all OK and I don't want to turn lazy loading off. But later I need to send some of the objects (actually one object) to the GWT…
Andrey Minogin
  • 4,521
  • 6
  • 38
  • 60
187
votes
8 answers

How do synchronized static methods work in Java and can I use it for loading Hibernate entities?

If I have a util class with static methods that will call Hibernate functions to accomplish basic data access. I am wondering if making the method synchronized is the right approach to ensure thread-safety. I want this to prevent access of info to…
tomato
  • 5,644
  • 13
  • 43
  • 48
187
votes
14 answers

Kotlin with JPA: default constructor hell

As JPA requires, @Entity classes should have a default (non-arg) constructor to instantiate the objects when retrieving them from the database. In Kotlin, properties are very convenient to declare within the primary constructor, as in the following…
hotkey
  • 140,743
  • 39
  • 371
  • 326
186
votes
10 answers

What's the difference between session.persist() and session.save() in Hibernate?

Can anyone tell me what's the advantage of persist() vs save() in Hibernate?
Anthony
  • 12,407
  • 12
  • 64
  • 88
181
votes
4 answers

What's the difference between JPA and Spring Data JPA?

I am a bit confused about the difference between Spring Data-JPA and JPA. I know about JPA that it is a specification for persisting the Java Objects to a relational database using popular ORM technology. In other words, JPA provides interfaces and…
Dhruv
  • 10,291
  • 18
  • 77
  • 126
178
votes
11 answers

Hibernate vs JPA vs JDO - pros and cons of each?

I'm familiar with ORM as a concept, and I've even used nHibernate several years ago for a .NET project; however, I haven't kept up with the topic of ORM in Java and haven't had a chance to use any of these tools. But, now I may have the chance to…
matt b
  • 138,234
  • 66
  • 282
  • 345
178
votes
7 answers

How to fetch FetchType.LAZY associations with JPA and Hibernate in a Spring Controller

I have a Person class: @Entity public class Person { @Id @GeneratedValue private Long id; @ManyToMany(fetch = FetchType.LAZY) private List roles; // etc } With a many-to-many relation that is lazy. In my controller I…
Matsemann
  • 21,083
  • 19
  • 56
  • 89
176
votes
6 answers

What is “the inverse side of the association” in a bidirectional JPA OneToMany/ManyToOne association?

In the example section of the @OneToMany JPA annotation reference: Example 1-59 @OneToMany - Customer Class With Generics @Entity public class Customer implements Serializable { ... @OneToMany(cascade=ALL, mappedBy="customer") public…
Behrang
  • 46,888
  • 25
  • 118
  • 160
175
votes
18 answers

How to set a default entity property value with Hibernate

How do I set a default value in Hibernate field?
Dejell
  • 13,947
  • 40
  • 146
  • 229
172
votes
41 answers

Error creating bean with name 'entityManagerFactory' defined in class path resource : Invocation of init method failed

When I compile my spring project, I got the following error. Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation…
thevikasdube
  • 1,723
  • 2
  • 10
  • 6