95,147 questions
1278
votes
14
answers
1.4m
views
What are the possible values of the Hibernate hbm2ddl.auto configuration and what do they do
I really want to know more about the update, export and the values that could be given to hibernate.hbm2ddl.auto
I need to know when to use the update and when not? And what is the alternative?
These ...
759
votes
18
answers
818k
views
Difference between FetchType LAZY and EAGER in Java Persistence API?
What is the difference between FetchType.LAZY and FetchType.EAGER in Java Persistence API?
646
votes
9
answers
639k
views
JPA JoinColumn vs mappedBy
What is the difference between:
@Entity
public class Company {
@OneToMany(cascade = CascadeType.ALL , fetch = FetchType.LAZY)
@JoinColumn(name = "companyIdRef", referencedColumnName ...
595
votes
15
answers
269k
views
What is the difference between DAO and Repository patterns?
What is the difference between Data Access Objects (DAO) and Repository patterns? I am developing an application using Enterprise Java Beans (EJB3), Hibernate ORM as infrastructure, and Domain-Driven ...
555
votes
25
answers
744k
views
How can I log SQL statements in Spring Boot?
I want to log SQL statements to a file.
I have the following properties in application.properties:
spring.datasource.url=...
spring.datasource.username=user
spring.datasource.password=1234
spring....
446
votes
5
answers
680k
views
Hibernate show real SQL [duplicate]
if I set
<property name="show_sql">true</property>
in my hibernate.cfg.xml configuration file in the console I can see the SQL.
But it's not real SQL... Can I see the SQL code that will ...
398
votes
10
answers
347k
views
What is the easiest way to ignore a JPA field during persistence?
I'm essentially looking for a "@Ignore" type annotation with which I can stop a particular field from being persisted. How can this be achieved?
387
votes
34
answers
426k
views
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 ...
362
votes
27
answers
760k
views
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 ...
333
votes
6
answers
605k
views
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 ...
318
votes
8
answers
185k
views
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 ...
315
votes
22
answers
164k
views
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/...
274
votes
14
answers
412k
views
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. ...
270
votes
5
answers
194k
views
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?
@...
264
votes
7
answers
199k
views
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?
246
votes
8
answers
459k
views
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 ...
242
votes
8
answers
249k
views
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?
229
votes
8
answers
235k
views
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 ...
224
votes
3
answers
223k
views
Make Hibernate ignore instance variables that are not mapped [duplicate]
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 ...
222
votes
7
answers
252k
views
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 ...
216
votes
8
answers
164k
views
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?
212
votes
5
answers
67k
views
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 ...
212
votes
10
answers
128k
views
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 ...
207
votes
4
answers
175k
views
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 ...
197
votes
10
answers
252k
views
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?