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
14
votes
1 answer

Are Hibernate Named Queries precompiled in the true sense?

Pre-compiled queries are compiled and cached in advance by DB vendor (like oracle,sql server etc) so that they can be faster for successive calls like prepared statement. In Hibernate Named queries are said to be pre-compiled at web server start up.…
M Sach
  • 33,416
  • 76
  • 221
  • 314
14
votes
3 answers

Java8 Collections.sort (sometimes) does not sort JPA returned lists

Java8 keeps doing strange things in my JPA EclipseLink 2.5.2 environment. I had to delete the question https://stackoverflow.com/questions/26806183/java-8-sorting-behaviour yesterday since the sorting in that case was influenced by a strange JPA…
Wolfgang Fahl
  • 15,016
  • 11
  • 93
  • 186
14
votes
1 answer

JPA: Predicate and expression both in QueryCriteria where clause

I have a situation where in my where clause I have single predicate and expression. And both needs to be ANDed in where clause: Expression col1 = tableEntity.get("col1"); Expression regExpr =…
user613114
  • 2,731
  • 11
  • 47
  • 73
14
votes
1 answer

Hibernate @Where is not enforcing at @MappedSuperClass Entity

For migrating from eclipse link to hibernate, I am looking for the equivalent of eclipse link annotation @AdditionalCriteria in Hibernate at @MappedSupperClass BaseEntity level, to filter logically deleted records from all entities extending this…
Bikram
  • 828
  • 8
  • 21
14
votes
2 answers

Pageable and @Param in a spring data JpaRepository method issue [2]

I'm aware of this question, but using org.springframework.data:spring-data-jpa:1.7.0.RELEASE I'm still having the same issue (Either use @Param on all parameters except Pageable and Sort typed once, or none at all!). My class is: public interface…
Pedro Dusso
  • 2,100
  • 9
  • 34
  • 64
14
votes
3 answers

Java 8 Date Time api in JPA

What is the best way how to integrate Java 8 Date Time api in jpa? I have added converters: @Converter(autoApply = true) public class LocalDatePersistenceConverter implements AttributeConverter { @Override public Date…
sandris
  • 1,478
  • 2
  • 18
  • 34
14
votes
2 answers

IntelliJ "Could not autowire." inspection, "[…] more than one bean" for Spring JPA repositories

In our code we have a number of Spring JPA repositories, one for each of our model classes. They are defined as (where is the name of our modal class): @Repository public interface Repository implements JpaRepository { …
Jonas Rabbe
  • 2,175
  • 1
  • 16
  • 14
14
votes
3 answers

Spring @Transactional not creating required transaction

Ok, so I've finally bowed to peer pressure and started using Spring in my web app :-)... So I'm trying to get the transaction handling stuff to work, and I just can't seem to get it. My Spring configuration looks like this:
Steve
  • 2,678
  • 8
  • 40
  • 54
14
votes
3 answers

JPA @ManyToMany - Cannot delete or update a parent row: a foreign key constraint fails

I have the Entities: @Entity public class User { @ManyToMany(cascade=CascadeType.PERSIST, fetch=FetchType.EAGER) private List roles = new ArrayList(); @Entity public class Role { @ManyToMany(cascade=CascadeType.PERSIST,…
James P.
  • 19,313
  • 27
  • 97
  • 155
14
votes
7 answers

Order by count using Spring Data JpaRepository

I am using Spring Data JpaRepository and I find it extremely easy to use. I actually need all those features - paging, sorting, filtering. Unfortunately there is one little nasty thing that seems to force me to fall back to use of plain JPA. I need…
makasprzak
  • 5,082
  • 3
  • 30
  • 49
14
votes
1 answer

left join with spring data jpa and querydsl

I am using spring data jpa and querydsl and trapped on how to write simple nice query to left join two tables. Suppose I have an Project entity and a Task entity with OneToMany relationship defined in Project, I would like to do something…
Frey Zheng
  • 171
  • 2
  • 2
  • 8
14
votes
2 answers

How to use prepared statement in JPA

I am a play framework application Developer.I am using createNativeQuery method in JPA. In this example i want to use prepared statement. Please anyone help me? Here is the code without JPA. I need help to convert it to Prepared statement. Query…
user3454863
  • 161
  • 1
  • 2
  • 10
14
votes
1 answer

Automatically convert a parameter with Spring Data JPA

In our entity beans we use a custom ID format which includes a checksum to verify that the ID is actually valid. Ids look like ID827391738979. To make sure that all code uses correct IDs only we created a code wrapper around an ID String: class ID…
Jan Thomä
  • 13,296
  • 6
  • 55
  • 83
14
votes
1 answer

When exactly does JPA REQUIRES_NEW transaction commit

In a spring container, with the code below: public class A { @Transactional public void m1() { ... b.m2(); // call in a new transaction ... } } public class B { @Transactional(propagation =…
Ahmad Y. Saleh
  • 3,309
  • 7
  • 32
  • 43
14
votes
2 answers

JPQL select query for ElementCollection

I have the following entity with enum collection. I would like to search the user with an enum parameter. The user might have multiple permission. When I search the users with the parameter like Permission.APPROVE, there may be one or more user who…
Zaw Than oo
  • 9,651
  • 13
  • 83
  • 131