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
2 answers

Are JPA (EclipseLink) custom types possible?

In particular I am interested in using PostgreSQLs json type. The core of the problem seems to be that there is no internal mapping in Eclipselink to json type. So, using a naive approach with: @Column(name = "json", columnDefinition =…
markdsievers
  • 7,151
  • 11
  • 51
  • 83
14
votes
1 answer

Enable no-proxy behaviour for all FetchType.LAZY non-collections by default in Hibernate

When using standard JPA annotations, you can specify FetchType.LAZY on non-collection fields (i.e. @ManyToOne and @OneToOne). It seems Hibernate internally uses "proxy" fetching in this case. But proxy fetching has its problems with inheritance and…
Alexey Andreev
  • 1,980
  • 2
  • 17
  • 29
14
votes
2 answers

@PreUpdate does not work with Spring Data JPA

I have an entity: @Entity @EntityListeners(MyEntityListener.class) class MyEntity{ ... } And the listener: class MyEntityListener{ @PrePersist @PreUpdate public void doSomething(Object entity){ ... } } I'm using the Spring Data…
fracz
  • 20,536
  • 18
  • 103
  • 149
14
votes
2 answers

Hibernate database specific columnDefinition values

the problem is as follows: We're using hibernate with annotations as O/R Mapper. Some @Column annotations look like: @Column(columnDefinition = "longblob", name = "binaryData", nullable = true) or @Column(columnDefinition = "mediumtext", name =…
user1946784
  • 1,397
  • 3
  • 14
  • 20
14
votes
6 answers

Hibernate - createNativeQuery with "non-entity class" result

I'm new to all this Hibernate/JPA stuff, so i will try to be as clear as possible. Is there any way in Hibernate to use createNativeQuery to select a single/or multiple fields in a query without using an Entity class as the return object ? I'm…
Joshua
  • 627
  • 4
  • 9
  • 21
14
votes
1 answer

ManyToMany (with additional columns) using @ElementCollection and java.util.Map?

I'm trying to optimize my @Entity classes. Let's take the common case of a User <-> Group relationship. I also want to store the date when the relation was established. The table layout: USER GROUP_USER GROUP ------ ------------ …
Benjamin M
  • 23,599
  • 32
  • 121
  • 201
14
votes
2 answers

JPA Criteria API: LEFT JOIN for optional relationships

I'm using the Criteria API basically the first time. It's about abstracting queries for a generic builder: public TypedQuery newQuery( Manager manager ) { CriteriaBuilder builder = this.entityManager.getCriteriaBuilder(); Class
Kawu
  • 13,647
  • 34
  • 123
  • 195
14
votes
7 answers

Hibernate HQL join fetch not recursively fetching

I have the following query and method private static final String FIND = "SELECT DISTINCT domain FROM Domain domain LEFT OUTER JOIN FETCH domain.operators LEFT OUTER JOIN FETCH domain.networkCodes WHERE domain.domainId =…
Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
14
votes
1 answer

Simple H2 and Hibernate/JPA

Simple test with H2 as the database, JPA and Hibernate. Gives no discerning error, but it does not persist the entity. For sure I am missing something extremely simple persistence.xml in META-INF/:
vlad dd
  • 155
  • 1
  • 1
  • 8
14
votes
2 answers

How to execute custom SQL query with spring-managed transactional EntityManager

I have an application built on Spring. I let the Spring do the all @Transactional magic and everything works fine as long as I operate on my entities that are mapped to Java objects. However, when I want to do some custom job on a table that is not…
fracz
  • 20,536
  • 18
  • 103
  • 149
14
votes
2 answers

Transaction management with Spring Batch

I am discovering actually Spring and I am able to setup some jobs. Now, I would like to save my imported datas in a database using Hibernate/JPA and I keep getting this error : 14:46:43.500 [main] ERROR o.s.b.core.step.AbstractStep - Encountered…
Dimitri
  • 8,122
  • 19
  • 71
  • 128
14
votes
4 answers

Last update timestamp with JPA

I'm playing around a bit with JPA(Eclipselink to be specific). The below entity have a timestamp that's supposed to reflect whenever that entity was last updated. What are the strategies for making JPA update that timestamp automatically every…
nos
  • 223,662
  • 58
  • 417
  • 506
14
votes
4 answers

JPA persistence.xml META-INF not working correctly

I am stumped when it comes to the location of my persistence.xml file. I am using eclipselink 2.4 as my JPA 2.0 implementation and have my persistence.xml located under src/main/resources/META-INF/persistence.xml as many posts state. The first…
Padawan
  • 770
  • 1
  • 8
  • 18
14
votes
3 answers

What is the difference between @Inject and @PersistenceContext?

In a project using JPA, I commonly use @Inject EntityManager em; in order to obtain such an object. I saw that many code snippets in the web instead use: @PersistenceContext EntityManager em; What is the difference between these options? My code…
Thiago Chaves
  • 9,218
  • 5
  • 28
  • 25
14
votes
4 answers

JPA Annotations in Android

We have a project that uses JPA/Hibernate on the server side, the mapped entity classes are in their own Library-Project and use Annotations to be mapped to the database. I want to use these classes in an Android-Project - is there any way to ignore…
dasmaze
  • 642
  • 1
  • 8
  • 16