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
243
votes
8 answers

How do we count rows using older versions of Hibernate (~2009)?

For example, if we have a table Books, how would we count total number of book records with hibernate?
craftsman
  • 15,133
  • 17
  • 70
  • 86
242
votes
8 answers

How to map a composite key with JPA and Hibernate?

In this code, how to generate a Java class for the composite key (how to composite key in hibernate): create table Time ( levelStation int(15) not null, src varchar(100) not null, dst varchar(100) not null, distance int(15) not…
kaaf
  • 2,421
  • 3
  • 15
  • 4
242
votes
4 answers

javax.transaction.Transactional vs org.springframework.transaction.annotation.Transactional

I don't understand what is the actual difference between annotations javax.transaction.Transactional and org.springframework.transaction.annotation.Transactional? Is org.springframework.transaction.annotation.Transactional an extension of…
stamis
  • 2,545
  • 2
  • 15
  • 9
231
votes
8 answers

How does JPA orphanRemoval=true differ from the ON DELETE CASCADE DML clause

I am a little confused about the JPA 2.0 orphanRemoval attribute. I think I can see it is needed when I use my JPA provider's DB generation tools to create the underlying database DDL to have an ON DELETE CASCADE on the particular relation. However,…
Markos Fragkakis
  • 7,499
  • 18
  • 65
  • 103
222
votes
18 answers

Is the buildSessionFactory() Configuration method deprecated in Hibernate?

When I updated the Hibernate version from 3.6.8 to 4.0.0, I got a warning about deprecated method buildSessionFactory() in this line: private static final SessionFactory sessionFactory = new…
pushistic
  • 3,406
  • 3
  • 21
  • 35
221
votes
3 answers

Make Hibernate ignore instance variables that are not mapped

I thought hibernate takes into consideration only instance variables that are annotated with @Column. But strangely today when I added a variable (that is not mapped to any column, just a variable i need in the class), it is trying to include that…
hese
  • 3,397
  • 8
  • 25
  • 34
216
votes
8 answers

Difference Between One-to-Many, Many-to-One and Many-to-Many?

Ok so this is probably a trivial question but I'm having trouble visualizing and understanding the differences and when to use each. I'm also a little unclear as to how concepts like uni-directional and bi-directional mappings affect the…
Ian Dallas
  • 12,451
  • 19
  • 58
  • 82
216
votes
44 answers

Hibernate - Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1

I get following hibernate error. I am able to identify the function which causes the issue. Unfortunately there are several DB calls in the function. I am unable to find the line which causes the issue since hibernate flush the session at the end of…
Sujee
  • 4,985
  • 6
  • 31
  • 37
214
votes
7 answers

Can someone explain mappedBy in JPA and Hibernate?

I am new to hibernate and need to use one-to-many and many-to-one relations. It is a bi-directional relationship in my objects, so that I can traverse from either direction. mappedBy is the recommended way to go about it, however, I couldn't…
brainydexter
  • 19,826
  • 28
  • 77
  • 115
212
votes
17 answers

What is the proper way to re-attach detached objects in Hibernate?

I have a situation in which I need to re-attach detached objects to a hibernate session, although an object of the same identity MAY already exist in the session, which will cause errors. Right now, I can do one of two…
Stefan Kendall
  • 66,414
  • 68
  • 253
  • 406
212
votes
4 answers

How to change a field name in JSON using Jackson

I'm using jackson to convert an object of mine to json. The object has 2 fields: @Entity public class City { @id Long id; String name; public String getName() { return name; } public void setName(String name){ this.name = name; } …
Ali
  • 12,354
  • 9
  • 54
  • 83
212
votes
10 answers

What are the differences between the different saving methods in Hibernate?

Hibernate has a handful of methods that, one way or another, takes your object and puts it into the database. What are the differences between them, when to use which, and why isn't there just one intelligent method that knows when to use what? The…
Henrik Paul
  • 66,919
  • 31
  • 85
  • 96
206
votes
14 answers

When and why JPA entities should implement the Serializable interface?

The question is in the title. Below I just described some of my thoughts and findings. When I had a very simple domain model (3 tables without any relations), all my entities did NOT implement the Serializable interface. But when the domain model…
Roman
  • 64,384
  • 92
  • 238
  • 332
197
votes
4 answers

What is the difference between Unidirectional and Bidirectional JPA and Hibernate associations?

What is the difference between Unidirectional and Bidirectional associations? Since the table generated in the db are all the same,so the only difference I found is that each side of the bidiretional assocations will have a refer to the other,and…
hguser
  • 35,079
  • 54
  • 159
  • 293
194
votes
5 answers

What is the "owning side" in an ORM mapping?

What exactly does the owning side mean? What is an explanation with some mapping examples (one to many, one to one, many to one)? The following text is an excerpt from the description of @OneToOne in Java EE 6 documentation. You can see the concept…
Just a learner
  • 26,690
  • 50
  • 155
  • 234