Questions tagged [jpa]

The Jakarta Persistence API (formerly Java Persistence API) (JPA) is a Java specification for accessing, persisting, and managing data between Java objects/classes and a relational database. JPA was defined as part of the EJB 3.0 specification as a replacement for the EJB 2 CMP Entity Beans specification. JPA is now considered the standard industry approach for Object to Relational Mapping (ORM) in the Java Industry.

The excerpt above is from Wikibooks:

Examples

The current version of the JPA specification is JPA 3.1, released on Apr 06, 2022.

Useful links

Related tags

FAQ

Spring Data JPA Update @Query not updating? While this question is about Spring Data JPA the underlying problem is about understanding the 1st level cache of JPA. See also the many duplicates pointing to that question.

One to many relationship doesn't work Spring boot jpa Again, asked in the context of Spring Data JPA it is really about JPA. It describes a common problem/misunderstanding with regard to bidirectional relationships.

51422 questions
13
votes
4 answers

Set optional parameters in JPQL Query

I got this list of coins that i want to filter with that 3 optional parameters(Currency, quantity and year) How can I set parameters in JPQL as optional? I dont want to do 9 "if else" for checking if its null I got the function filtradoMonedas…
Nacho Martin
  • 131
  • 1
  • 1
  • 3
13
votes
1 answer

What does "org.hibernate.DuplicateMappingException" error mean?

I'm trying to force JPA/Hibernate to generate and use only lowercase tablenames. I've implemented a NamingStrategy like this: public class MyNamingStrategy extends DefaultNamingStrategy { @Override public String classToTableName(String…
Bogdan
  • 5,368
  • 9
  • 43
  • 62
13
votes
5 answers

JPA Static Metamodel not recognized by IntelliJ

I generated the application with JHipster with Gradle as the build tool. When I created entity I added filtering support, which generated JPA static metamodel. But IntelliJ doesn't recognize the metamodels. I have enabled the annotation processor…
A0__oN
  • 8,740
  • 6
  • 40
  • 61
13
votes
5 answers

Spring data - enable optimistic locking

Note: I DON'T NEED AN EXPLANATION CONCERNING THE OPTIMISTIC LOCKING. This question is about what seems to be a specific Spring Data behavior when using optimistic locking. From the jpa specs whenever an entity has a @Version annotated field,…
vratojr
  • 818
  • 2
  • 8
  • 25
13
votes
4 answers

Hibernate - unable to find Entity with ID

I'm retreiving some data from the database in my DAO with this method : @Override @Transactional public List findLastHistoriesByCount(int gHistoriesCount) { List result = new ArrayList(); result = entityManager …
OddDev
  • 1,521
  • 7
  • 23
  • 45
13
votes
3 answers

How to delete entity with JOINs using JPA and Hibernate

I have following entities: I want to delete WordSet by id and username of the user using JPA. Here is entity declarations: User @Entity @Data @ToString(callSuper = true) @EqualsAndHashCode(callSuper =…
solomkinmv
  • 1,804
  • 3
  • 19
  • 30
13
votes
4 answers

How to make QueryDSL and Lombok work together

When a method or variable is annotated with Lombok annotation, the maven plugin will complain by processing the source generation for JPA. I get this kind of failure in the console logs: symbol: class __ location: class…
jchrbrt
  • 1,006
  • 1
  • 11
  • 12
13
votes
3 answers

JPA (Hibernate) and custom table prefixes

Is it possible to override table names in JPA/Hibernate in order to add a common prefix for all project entities? For instance to be able to prefix all JBPM 5 tables by "JBPM5_" prefix. Example for the accepted answer: public class…
Mike Minicki
  • 8,216
  • 11
  • 39
  • 43
13
votes
2 answers

Hibernate: LazyInitializationException: failed to lazily initialize a collection of role. Could not initialize proxy - no Session

I have next error: nested exception is org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.example.Model.entities, could not initialize proxy - no Session My Model entity: class Model { ... …
Orest
  • 6,548
  • 10
  • 54
  • 84
13
votes
1 answer

Specifying Result limit using JPA Specification

Is there possibility to use limit or setMaxResults using Spring-Data-JPA Specification? I can use it via Criteria or JPQL, but I need only via specifications. Specifications have CriteriaQuery, not a Query. So, there is no setMaxResults method.
Squeez
  • 919
  • 2
  • 12
  • 30
13
votes
3 answers

Implement AttributeConverter for Generic Class with @Converter

How do I implement AttributeConverter for Generics? Something Like class JSONConverter implements AtttributeConverter{ //Here How do I get the generic class type with which I can convert a serialized object } call the converter in…
madhairsilence
  • 3,787
  • 2
  • 35
  • 76
13
votes
3 answers

Is there a way to use Postgres' UUID generation with Hibernate's IDENTITY ID generation strategy?

I'm using Spring Boot 1.4.1, which includes Hibernate 5, with Postgres 9.6, and I'm trying to create an entity with a UUID ID but using Postgres' UUID generation instead of Hibernate's. Many similar questions say to set the column type as pg-uuid.…
Strengthiness
  • 561
  • 1
  • 5
  • 12
13
votes
3 answers

What would cause an Hibernate InvalidStateException

I get this error, even though there are no validation constraints in my model class (all of the member variables are set properly but I stil get this exception on object creation). How do I debug this error? javax.el.ELException:…
Sam
  • 8,387
  • 19
  • 62
  • 97
13
votes
3 answers

JPA many to many with extra column

I have a following problem that I need to solve. The core issues is that I want to add additional column into JoinTable for ManyToMany relation in JPA. In my case I have following entities. The Topic is a simple entity which has many…
endryha
  • 7,166
  • 8
  • 40
  • 64
13
votes
2 answers

Spring Data JPA Pageable with named entity graph

I am using Spring data with JPA 2.1 to retrieve the entities with pagination & specification (criteria builder) using below method: Page findAll(Specification spec, Pageable pageable) How can i specify @EntityGraph on this method? Rightnow,…
suraj bahl
  • 2,864
  • 6
  • 31
  • 42