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

Extend an entity class in JPA throws Unknown column 'DTYPE' in 'field list' error

@Entity @Table(name = "PERSON") @Inheritance(strategy=InheritanceType.SINGLE_TABLE) public class Person { @Id @GeneratedValue @Column(name = "PERSON_ID") private Long personId; @Column(name = "FIRSTNAME") private…
Cork Kochi
  • 1,783
  • 6
  • 29
  • 45
14
votes
2 answers

DDD, JPA and Multi-Module Maven

I'm trying to configure and Maven multi-module project with Spring / JPA. Here's the general layout. I have a root module with 5 children modules. backoffice (root maven module) | -(maven module)-----core (this is where persistence.xml and…
user523078
  • 227
  • 3
  • 7
14
votes
4 answers

How to set @CreatedDate in the past (for testing)

My spring-data-jpa backend has a class that populates the (test) database with a lot of test data. The class usese the spring data repositories to create entities. All my entities have a field annotated with @CreatedData and the corresponding…
Robert
  • 1,579
  • 1
  • 21
  • 36
14
votes
4 answers

Should Hibernate be able to handle overlapping foreign keys?

I have a table that has two foreign keys to two different tables with both foreign keys sharing one column: CREATE TABLE ZipAreas ( country_code CHAR(2) NOT NULL, zip_code VARCHAR(10) NOT NULL, state_code VARCHAR(5) NOT NULL, city_name…
Kawu
  • 13,647
  • 34
  • 123
  • 195
14
votes
2 answers

Spring boot Jpa: hibernate as default?

if one uses the spring-boot-starter-data-jpa dependency and extends repository classes by org.springframework.data.jpa.repository.JpaRepository, is this 'plain jpa' or hibernate? What is the difference?
yN.
  • 1,847
  • 5
  • 30
  • 47
14
votes
4 answers

JPA criteria API order by NULL last

I use JPA criteria API to fetch records from the datebase. I have entity Record with field dateTime which can be null. I would code: public List find(RecordFilter recordFilter, int page, int pageSize) { CriteriaBuilder criteriaBuilder =…
Yan Khonski
  • 12,225
  • 15
  • 76
  • 114
14
votes
2 answers

Hibernate @Id via inheritance

I'm trying to duplicate something you can do in .Net but not having much luck. Is the following not possible in Java or am I just missing something? When I run it I get told there is no identifier specified for entity Group. public abstract class…
Shane Courtrille
  • 13,960
  • 22
  • 76
  • 113
14
votes
3 answers

Bind array param to native query

I have table product_spec_entry with following columns: product_spec_id commodity_spec_id for one product_spec_id may be several commodity_spec_id, for example: |product_spec_id | commodity_spec_id| |----------------|------------------| |1683 …
HAYMbl4
  • 1,450
  • 2
  • 15
  • 29
14
votes
1 answer

JPA/Metamodel: Strange (inconsistent ?) example in Sun Docs

In Sun Online resources, they provide son example about the usage of the Criteria/Metamodel API, but as far as I understand Java, it seems to be impossible to work: CriteriaQuery cq = cb.createQuery(Pet.class); Metamodel m =…
Kevin
  • 4,618
  • 3
  • 38
  • 61
14
votes
6 answers

REST: how to serialize a java object to JSON in a "shallow" way?

Suppose I have the following JPA entities: @Entity public class Inner { @Id private Long id; private String name; // getters/setters } @Entity public class Outer { @Id private Long id; private String name; @ManyToOne private Inner…
Alvin Thompson
  • 5,388
  • 3
  • 26
  • 39
14
votes
2 answers

SELECT DISTINCT + ORDER BY in JPA 2 Criteria API

I've a class Lawsuit, that contains a List, each one with a Date attribute. I need to select all the Lawsuits ordered by the date of their Hearings I've a CriteriaQuery like CriteriaBuilder cb =…
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
14
votes
3 answers

Multiple column IN clause spring data jpa

Is it possible to have multiple columns in IN clause? @Query(nativeQuery = true, value = "select * from table where (column1, column2) in (:column1, :column2)") List findByColumn1Column2In(@Param("column1") List column1,…
HashimR
  • 3,803
  • 8
  • 32
  • 49
14
votes
4 answers

Hibernate: duplicate key value violates unique constraint

I am trying to insert into a new record to my postgresql using Hibernate and Java EE. This is my model: @Entity @SuppressWarnings("serial") @Inheritance(strategy=InheritanceType.JOINED) public class BaseDesign implements Serializable { @Id …
VHanded
  • 2,079
  • 4
  • 30
  • 55
14
votes
3 answers

JPA ManyToMany unidirectional relationship

Lets say we have two Entities, Entity Node and Entity Cluster. A Cluster has many Nodes. A Node can belong to multiple Cluster. So in Cluster there is a @ManyToMany annotation. However Node is unaware of any Cluster it belongs to (intentional). When…
dumb_terminal
  • 1,815
  • 1
  • 16
  • 27
14
votes
3 answers

JPA Uppercase table names

I have a table in Postgresql: CREATE TABLE "UTILISATEUR"( "IdUtilisateur" serial NOT NULL, "Nom" character varying(50), "Prenom" character varying(50), "Profil" character varying(50), "Pseudo" character varying(20), "IdSite" integer DEFAULT…
Kamel Mili
  • 1,374
  • 3
  • 19
  • 43