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
356
votes
33 answers

Hibernate - A collection with cascade=”all-delete-orphan” was no longer referenced by the owning entity instance

I'm having the following issue when trying to update my entity: "A collection with cascade=”all-delete-orphan” was no longer referenced by the owning entity instance". I have a parent entity and it has a Set<...> of some children entities. When I…
axcdnt
  • 14,004
  • 7
  • 26
  • 31
356
votes
37 answers

org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set

I am trying run a spring-boot application which uses hibernate via spring-jpa, but i am getting this error: Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set at…
Kleber Mota
  • 8,521
  • 31
  • 94
  • 188
334
votes
6 answers

What's the difference between Hibernate and Spring Data JPA

What are the main differences between Hibernate and Spring Data JPA? When should we not use Hibernate or Spring Data JPA? Also, when may Spring JDBC template perform better than Hibernate and Spring Data JPA?
hard coder
  • 5,449
  • 6
  • 36
  • 61
333
votes
24 answers

PersistentObjectException: detached entity passed to persist thrown by JPA and Hibernate

I have a JPA-persisted object model that contains a many-to-one relationship: an Account has many Transactions. A Transaction has one Account. Here's a snippet of the code: @Entity public class Transaction { @Id @GeneratedValue(strategy =…
Paul Sanwald
  • 10,899
  • 6
  • 44
  • 59
313
votes
8 answers

Hibernate SessionFactory vs. JPA EntityManagerFactory

I am new to Hibernate and I'm not sure whether to use a Hibernate SessionFactory or a JPA EntityManagerFactory to create a Hibernate Session. What is the difference between these two? What are the pros & cons of using each of those?
elpisu
  • 3,135
  • 3
  • 15
  • 5
312
votes
22 answers

JPA and Hibernate - Criteria vs. JPQL or HQL

What are the pros and cons of using Criteria or HQL? The Criteria API is a nice object-oriented way to express queries in Hibernate, but sometimes Criteria Queries are more difficult to understand/build than HQL. When do you use Criteria and when…
cretzel
  • 19,864
  • 19
  • 58
  • 71
310
votes
18 answers

Creation timestamp and last update timestamp with Hibernate and MySQL

For a certain Hibernate entity we have a requirement to store its creation time and the last time it was updated. How would you design this? What data types would you use in the database (assuming MySQL, possibly in a different timezone that the…
ngn
  • 7,763
  • 6
  • 26
  • 35
296
votes
6 answers

What is the difference between JOIN and JOIN FETCH when using JPA and Hibernate

Please help me understand where to use a regular JOIN and where a JOIN FETCH. For example, if we have these two queries FROM Employee emp JOIN emp.department dep and FROM Employee emp JOIN FETCH emp.department dep Is there any difference between…
abbas
  • 6,453
  • 2
  • 40
  • 36
291
votes
5 answers

How does spring.jpa.hibernate.ddl-auto property exactly work in Spring?

I was working on my Spring boot app project and noticed that, sometimes there is a connection time out error to my Database on another server(SQL Server). This happens specially when I try to do some script migration with FlyWay but it works after…
METTAIBI
  • 3,201
  • 5
  • 22
  • 29
279
votes
24 answers

How to fix org.hibernate.LazyInitializationException - could not initialize proxy - no Session

I get the following exception: Exception in thread "main" org.hibernate.LazyInitializationException: could not initialize proxy - no Session at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:167) at…
Blerta Dhimitri
  • 3,253
  • 5
  • 22
  • 33
271
votes
15 answers

Hibernate throws org.hibernate.AnnotationException: No identifier specified for entity: com..domain.idea.MAE_MFEView

Why am I getting this exception? package com.domain.idea; import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.JoinColumn; import javax.persistence.OneToOne; import…
Ramy
  • 20,541
  • 41
  • 103
  • 153
268
votes
14 answers

How do you do a limit query in JPQL or HQL?

In Hibernate 3, is there a way to do the equivalent of the following MySQL limit in HQL? select * from a_table order by a_table_column desc limit 0, 20; I don't want to use setMaxResults if possible. This definitely was possible in the older…
stevedbrown
  • 8,862
  • 8
  • 43
  • 58
264
votes
4 answers

Confusion: @NotNull vs. @Column(nullable = false) with JPA and Hibernate

When they appear on a field/getter of an @Entity, what is the difference between them? (I persist the Entity through Hibernate). What framework and/or specification each one of them belongs to? @NotNull is located within…
rapt
  • 11,810
  • 35
  • 103
  • 145
264
votes
7 answers

What are the First and Second Level caches in (N)Hibernate?

Can anyone explain in simple words what First and Second Level caching in Hibernate/NHibernate are?
suhair
  • 10,895
  • 11
  • 52
  • 63
252
votes
12 answers

How can I make a JPA OneToOne relation lazy

In this application we are developing, we noticed that a view was particularly slow. I profiled the view and noticed that there was one query executed by hibernate which took 10 seconds even if there only were two object in the database to fetch.…
KCL
  • 6,733
  • 10
  • 37
  • 43