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

JPA: BeanCreationException: OneToMany & ManyToOne mapping JPA / Hibernate

I have two tables with foreign key relations. I've tried searching on how to do it and it always leads to OneToMany & ManyToOne mapping. I have these two tables. user_role user I'm trying to display all the users and show their position by getting…
14
votes
7 answers

High Level Java Client selection for Apache Cassandra

There are four high level APIs to access Cassandra and I do not have time to try them all. So I hoped to find somebody who could help me to choose the proper one. I'll try to write down my findings about…
andreas
  • 1,483
  • 1
  • 15
  • 36
14
votes
4 answers

How to prevent changes of entity relationships?

I am using spring boot for to store complex json-structures via JPA in our database. The root of the json-structure represents a "House" object. A "House" object contains several "Furnitures". For example: House ID: 4711 |- Furniture: ID 4712 (with…
slartidan
  • 20,403
  • 15
  • 83
  • 131
14
votes
1 answer

Does PESSIMISTIC_WRITE lock the whole table?

Just to be sure that I correctly understand how things work. If I do em.lock(employee, LockModeType.PESSIMISTIC_WRITE); - will it block only this entity (employee) or the whole table Employees? If it matters, I am talking about PostgreSQL.
Andremoniy
  • 34,031
  • 20
  • 135
  • 241
14
votes
5 answers

SQL Server 2016 - Invalid object name 'hibernate_sequence'

I have an image backup that I restore to the MS SQL server 2016. I have an entity that declares its id like that: @Id @GeneratedValue(strategy = GenerationType.AUTO) @XmlID @XmlElement @XmlJavaTypeAdapter(IntToStringXmlAdapter.class) private Integer…
Investigator
  • 1,431
  • 2
  • 17
  • 24
14
votes
4 answers

Google App Engine App with JPA deployment hangs

I have a java GAE web app with datanucleus as the JPA provider. When deploying locally on my machine - the deployment hangs (takes minutes). Looking at the task manager I have a javac process running. Any idea what is going wrong?
Cristi
  • 141
  • 2
14
votes
3 answers

Jackson triggering JPA Lazy Fetching on serialization

We have a back-end component that exposes database (PostgreSQL) data via JPA to RESTful API. The problem is that when sending a JPA entity as a REST response, I can see Jackson triggering all Lazy JPA relationships. Code example…
Sam
  • 1,832
  • 19
  • 35
14
votes
3 answers

Persisting a @OneToOne child entity with @MapsId throws "error:detached entity passed to persist" in Hibernate

I read https://vladmihalcea.com/the-best-way-to-map-a-onetoone-relationship-with-jpa-and-hibernate/. I tried suggestion config like(using spring data JPA,hibernate 5.0 as vendor ): public class PaperSubjectType{ @Id private Long id; …
yuxh
  • 924
  • 1
  • 9
  • 23
14
votes
3 answers

JPA / Hibernate unidirectional one-to-one mapping with shared primary key

I'm having a very hard time trying to get a unidirectional one-to-one relationship to work with JPA (Provider: Hibernate). In my opinion this should not be too much of a hassle but apparently JPA / Hibernate disagrees on that ;-) The problem is that…
Korgen
  • 5,191
  • 1
  • 29
  • 43
14
votes
3 answers

JPQL query - hibernate: with-clause not allowed on fetched associations

I have JPA Repository and JPQL query like this: @Query("SELECT c from Campaign c" + " left join fetch c.postsList p on p.status = :postStatus" + " left join fetch p.platform" + " left join fetch c.campaignStatistics stat on…
Peter Kozlovsky
  • 633
  • 2
  • 10
  • 28
14
votes
1 answer

How to generate Custom Id in JPA

i want generate Custom Id in JPA it must be primary key of table. there are many examples to create Custom Id using hibernate like this i want same implementation but in JPA.The id must be alphanumeric like STAND0001 Thanks.
Amol Raje
  • 928
  • 3
  • 9
  • 16
14
votes
4 answers

Error in NamedStoredProcedureQuery in Spring JPA - "Found named stored procedure parameter associated with positional parameters"

I am trying to call a Stored Procedure written in Postgresql using the NamedStoredProcedureQuery provided by Spring JPA. Following are code snippets. EntityMovement.java @Entity @Table(name = "entity_movement") @NamedStoredProcedureQueries({ …
PriyaAnil
  • 161
  • 1
  • 1
  • 6
14
votes
3 answers

JPA foreign key NOT AS OBJECT

I have two simple tables in MySQL User ---(one-to-many)--- Expense I am using Spring JPA to generate theses two entities. Expense has 'user_id' foreign key field which references 'id' field in User table. I use JSON in requests to populate…
Alexandr Zhurkov
  • 474
  • 5
  • 19
14
votes
2 answers

Confusion between JPA and Hibernate cascading

I'm using Hibernate 3.6 and have my code annotated (versus using hibernate mapping files). I ran into the known "problem" of using JPA cascading options that are not compatible with Hibernate's CascadeType (see this link for more info…
Gordon
  • 1,210
  • 5
  • 16
  • 23
14
votes
18 answers

Spring Boot: does @Entity Annotation exist?

I watched this Spring Boot tutorial: https://javabrains.io/courses/spring_bootquickstart/lessons/Creating-a-Spring-Data-JPA-Repository and it puts an @Entity annotation before a class name. When I tried to do it in my code, I got an Error saying…
CrazySynthax
  • 13,662
  • 34
  • 99
  • 183