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

How to create an 'instance of' -like query in JPA 2.0?

Say we've got an abstract @Entity Animal, and several entity classes that extend Animal, including Dog, Cat, Monkey and Bat. How can I filter the results based on the extending entity's class? Example: There are checkboxes where the user can select…
Kimi
  • 6,239
  • 5
  • 32
  • 49
13
votes
5 answers

What impact does the @embedded annotation mean?

How does the Embedded annotation affect the database? How will SQL queries need to change? What's the typical usecase for using the annotation?
user48545
  • 3,291
  • 9
  • 31
  • 42
13
votes
2 answers

Jpa - Hibernate @Version incorrectly incremented

I'm using jpa with hibernate (3.2.7) as orm implementation. I have an entity being modified and then merged. I also have an @EntityListeners on this entity to ensure some attribute being valued. If I change a value before merge, and then change back…
zime
  • 171
  • 1
  • 5
13
votes
4 answers

Bean Validation constraint(s) violated while executing Automatic Bean Validation on callback event: 'prePersist'

I created an EJB Session facade in my Netbeans 7 for saving my entity. I have a manytoone mapping between my Insurance and RatePlan Class. public class Insurance{ @ManyToOne(optional=false) @JoinColumn(name="PLAN_ID") private RatePlan…
Mark Estrada
  • 9,013
  • 37
  • 119
  • 186
13
votes
7 answers

Get hold of a JDBC Connection object from a Stateless Bean

In a Stateless Session Bean an EntityManager is injected but I would like to get hold of a Connection object in order to invoke a DB Procedure. Is there any solution to this ?
Radu Stoenescu
  • 3,187
  • 9
  • 28
  • 45
13
votes
3 answers

Play, Hibernate and Evolutions

I've no previous experience with tools like Liquibase and similar. Up to now the way I've usually managed deployment into production on apps using Hibernate was using manual SQL to modify the tables, as they were quite simple apps (the complex ones…
Pere Villega
  • 16,429
  • 5
  • 63
  • 100
13
votes
3 answers

org.hibernate.hql.ast.QueryTranslatorImpl list ATTENTION: firstResult/maxResults specified with collection fetch; applying in memory

I'm facing a problem, I have a query in JPA. as I have some collections I need to use left join fetch or inner join fetch My problem is in using the setFirstResult and setMaxResult in order to bring back a precise number of result. every time i see…
Yannick Eurin
  • 199
  • 1
  • 1
  • 7
13
votes
2 answers

Execute a Create Table Query through the JPA EntityManager

I need to create a new Table in a Database I access through a JPA EntityManager. Do JPA NativeQueries support Queries other than "Select" or "Update"? Or is there another state-of-the-art way to execute a complex SQL query in a JPA Context?
Laures
  • 5,389
  • 11
  • 50
  • 76
13
votes
1 answer

'one to many' / 'many to many' attribute value type should not be '? extends'

I'm trying to define a simple Hibernate Mapping using Annotations in Kotlin. But my Many-To-Many Relation is not working as expected. Causing the following error in IntelliJ IDEA: 'one to many' / 'many to many' attribute value type should not be '?…
twobiers
  • 1,057
  • 1
  • 11
  • 27
13
votes
2 answers

Error: Getters of lazy classes cannot be final Kotlin Spring Boot

I try to create REST Spring Boot Server on Kotlin.I used database - first and automatically generated entities using the built-in Intellij tool. When starting the server pop-up error: 2020-01-12 15:09:14.387 ERROR 23016 --- [ restartedMain]…
apelsinkach
  • 123
  • 1
  • 1
  • 11
13
votes
4 answers

OneToOne between two tables with shared primary key

I'm trying to set up the following tables using JPA/Hibernate: User: userid - PK name Validation: userid - PK, FK(user) code There may be many users and every user may have max one validation code or none. Here's my classes: public class User…
Jonas
  • 343
  • 1
  • 4
  • 15
13
votes
3 answers

Should I let JPA or the database cascade deletions?

Let's say we have two entities, A and B. B has a many-to-one relationship to A like follows: @Entity public class A { @OneToMany(mappedBy="a_id") private List children; } @Entity public class B { private String data; } Now, I want to…
Rasmus Franke
  • 4,434
  • 8
  • 45
  • 62
13
votes
1 answer

Can I mix both update and insert in saveAll from JpaRepository

I am using Spring Boot and Spring Data JPA and Hibernate as the persistence provider. I have extended my Repository interface with JPARepository. I have a list of Entity Bean for a table. Some of them already exist and some of them not. I want to…
Jafar Ali
  • 1,084
  • 3
  • 16
  • 39
13
votes
4 answers

Converting Lazy Loaded object to JSON in spring boot jpa

I am getting error while sending the Lazy loaded object as a JSON in response to REST request in spring boot. When I request from browser to fetch the parentTree and call get method to get the version to test the lazy loading and return version but…
Developer
  • 493
  • 2
  • 8
  • 19
13
votes
2 answers

Can not persist data model's field into database, but can retrieve it

I have a problem when trying to persist a data model class into a database. I have a class like this: class DataModelClass{ //some more field etc. @Column(name = "number1", nullable = true) private Integer number1; @Column(name =…
Suule
  • 2,197
  • 4
  • 16
  • 42