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.
52,163
questions
0
votes
0
answers
6
views
Title: Improving Performance for Netting and Settlement Cron Job in Spring JPA
I am working on a netting and settlement process in the banking and finance sector. Specifically, I need to run a cron job every 4 hours and 15 minutes to retrieve data from the transaction table for ...
0
votes
0
answers
5
views
Hibernate: Generate non-id value from sequence
I have an entity with 2 fields which both use the same sequence, but when debugging I see that only the id field value is being generated:
@Table(name = "MY_TABLE")
public class MyEntity {
...
0
votes
0
answers
3
views
release conenction in JPA multitenancy connection provider
How to handle exception in releaseConenction(String tenantIdentifier, Connection connetcion) method which implements MultiTenantConnectionProvider. How do we ensure the connetcion will be closed if ...
0
votes
0
answers
8
views
Nested Interface Projections in Spring Data JPA
I am working on a spring boot based application where I want to utilize interface based projection as I want to select partial column from my mysql database.
I have a CourseEntity.java class with a ...
0
votes
0
answers
11
views
javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not extract ResultSet
Here the error:
javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not extract ResultSet
at org.hibernate.internal.ExceptionConverterImpl.convert(...
0
votes
1
answer
24
views
JPA EntityExistsException thown when saving and object
I have the following 2 objects in my project that share the common Composite Primary Key as and ID:
@Entity
@Immutable
@Cacheable(true)
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
@Table(name = ...
0
votes
0
answers
7
views
QueryDSL join(a, b) vs join(b).on(): Why does @SQLRestriction behave differently?
Intro:
I'm using QueryDSL with Hibernate in a Spring Boot project. I've noticed a difference in the way @SQLRestriction is applied when using join(a, b) versus join(b).on(). Specifically, when using ...
0
votes
0
answers
45
views
Fix naming convention to remove underscores from Hibernate JPA
Without any changes it was prepending the class UserProfile and BaseModel id (user_profile_id). What I wanted was just ID in the table. When I changed to use
<property name="...
-1
votes
1
answer
22
views
Issue with Changing @Table Annotation to "users" in JPA Entity Class Using H2 Database
I'm encountering an issue with my Java application where changing the @Table name in my entity class causes the application to fail during tests and runtime. Here are the details:
Originally, my ...
-1
votes
0
answers
11
views
Row updated in another transaction error unless there is a breakpoint on the save method
I have 2 methods that update an entity and have similar functionality, but I have inherited the codebase with little testing so don’t want to do a refactor yet.
However, there is a bug in one of these ...
0
votes
1
answer
16
views
JPA Subquery return object and use on query multiselect
I'm have a java spring application that use a criteria query. The query has a multiselect and one of the values is a subquery that bring an complete entity. The application work on original enviroment ...
-2
votes
1
answer
30
views
JPA get highest value in column with where condition
I'm using a JpaRepository to access a table in my database. I defined the table through an entity. My goal is, to get the highest value in the wordNumber column. But I also have to distinguish entries ...
0
votes
1
answer
28
views
How to Handle Indexes for @MapsId in JPA: Should FK and PK Share the Same Index?
I am using the @MapsId annotation in JPA to map a foreign key (FK) to a primary key (PK). According to the @MapsId annotation, the FK and PK share the same value. However, when I checked the database ...
-2
votes
0
answers
22
views
How to set foreign key constraint order by JPA annotation? [closed]
I'm using JPA in a Spring-Boot application with JPA (jakarta.persistence Annotations).
The creation of my DB schema (hbm2ddl=create) failed with an:
⚡ Foreign key constraint is incorrectly formed ...
0
votes
0
answers
35
views
JPQL did not translated to SQL correctly when using Window Functions
Models:
@Entity
@Data
//This is main entity
public class Collection {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
@OneToMany(mappedBy = &...
-1
votes
2
answers
39
views
any scenario's to use @Transactional annotation at Repository delete method?
I am reveiewing the code for one of the senior member for the first peer review so he added @Transactional annotation at custom repository with delete method. The custom Repository delete method is ...
-1
votes
0
answers
22
views
JPA Unit Test Error: Table not found During ALTER TABLE Execution
I am encountering an error in a simple JPA unit test where it attempts to execute an ALTER TABLE command on a table that it claims does not exist. Here is the relevant error message:
INFO: Property ...
0
votes
0
answers
31
views
Issuse with relationship mapping MapKeyEnumerated with an Entity List as values
I have this Entity
@Entity
public class MealPlanADay {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@JsonIgnore
private Long id;
//@OneToMany(cascade = CascadeType.ALL,...
0
votes
0
answers
24
views
Hibernate seems to ignore the dialect I specify
I'm using Olingo JPA for producing an OData API.
The database I'm connecting to doesn't support the 'LOCATE' function; instead it implements 'POSITION'.
This seems to be true of a few databases: ...
0
votes
0
answers
28
views
How to Convert a Complex SQL Query to Hibernate Criteria API
I'm learning about Hibernate's Criteria API and would like to know how to convert this particular SQL query to Criteria API. Here is the SQL query I’m working with:
select s1.score as score,count(s1....
0
votes
1
answer
26
views
Can i customize result of @ManyToMany of entity?
Here is 2 entity obj:
import jakarta.persistence.*;
import lombok.*;
import java.util.Set;
@Entity
@Table(name = "category"
, uniqueConstraints = {
@UniqueConstraint(...
0
votes
1
answer
65
views
IntelliJ IDE Cannot Find javax.annotation.processing.Generated Symbol While mvn test Works Correctly
I am having a problem with my project configuration and running the program and unit test. When running with mvn test the JUnit test executes propertly, but when executing from within the IntelliJ IDE,...
0
votes
1
answer
13
views
JPA, removing parent cannot remove all children
I have a @OneToOne relation between Parent and Child tables , I need to delete all child if happen delete on parent because children doesn't have meaning without parent !
Parent Entity :
@Entity(name =...
0
votes
0
answers
21
views
Impossible to use DATEDIFF in java JPA criteria queries?
For the life of me, I cannot figure this out.
I want to select entities from my H2 database, and get the difference between an entities timestamp column and a passed parameter.
trying
var dateDiff = ...
-1
votes
0
answers
168
views
java: cannot find symbol - symbol: class Generated location: package javax.annotation.processing during build
What are the possible errors that are causing this:
/home/api/target/generated-sources/annotations/org/example/core/user/model/User_.java:3:35
java: cannot find symbol
symbol: class Generated
...
0
votes
0
answers
15
views
Handling Date comparisons in MYSQL 8 and Spring boot without Milliseconds
We are upgrading our project from Mysql 5 to Mysql 8. there is weird issue coming in db queries in date handling.
On MySQL 5, while saving data to db, the date used to be saved with 'yyyy-MM-dd HH:mm:...
-1
votes
1
answer
47
views
Why does VsCode generate classes with both jakarta.data.metamodel and jakarta.persistence.metamodel?
For some time now, I've had a problem in VsCode where I end up with duplicate generated sources.
For example, let's take the SiteEntity entity.
In /target/generated-sources/annotations/com/.../sites, ...
0
votes
0
answers
29
views
Hibernate generating N(N+1) Updates for each Insert
On Hibernate 6.4.4 and 6.4.9, I am observing the following odd behavior.
In a loop, I am doing the following:
for (loop control) {
SomeObject object = new SomeObject(contents);
repository....
-2
votes
0
answers
127
views
Unable to open JDBC Connection for DDL execution ["encrypt" property is set to "true" and "trustServerCertifi
10:12:20 PM: Executing ':ReportingApplication.main()'...
> Task :compileJava UP-TO-DATE
> Task :processResources UP-TO-DATE
> Task :classes UP-TO-DATE
> Task :ReportingApplication.main()
...
-1
votes
0
answers
18
views
How do i switch between different schemas in spring jpa and hibernate dynamically
i have a multi tenancy application written with spring boot, keycloak, flyway and postgres, i have been finding it difficult to switch from one schema to another, note i have done a lot of research ...
-1
votes
0
answers
16
views
spring boot data jpa batch insert performance issue - improvement suggestion
I am facing an issue while inserting 1,00,000 records at once using spring data JPA repository. When we execute repository save-all method with list of objects, it is taking a lot of time if we use ...
0
votes
0
answers
26
views
UPSERT native SQL query for Collection as @Param of JPA Repository method
I need to iterate over collection of Enteties and apply UPSERT for each element atomically. As i see it - just need to send this collection into SQL query by SpEL.
I know, what i can iterate over ...
-1
votes
0
answers
35
views
Hibernate + Spring Boot: Handling "More than one row with the given identifier was found" Exception
I'm working on a Spring Boot application with Hibernate and encountering an issue where Hibernate throws "More than one row with the given identifier was found" exception. I'm using custom ...
0
votes
1
answer
24
views
Entity Inheritance and query filtering
I'm trying to achieve a very basic from SQL point of view operation but using Spring Boot and JPA
This is my Java data model:
@MappedSuperclass
public abstract class BaseEntity {
@Id
@...
1
vote
1
answer
50
views
Issue with @ManyToOne Lazy Loading: Unable to Find Entity by ID
Edit
I added an attribute that can be the problem, it had the same column name in the yEntity and the xEntity, but he is not part of the relationship (the Integer yEntity in yEntity who is a reference ...
0
votes
0
answers
29
views
Why does Blaze-Persistence project count queries for pagination despite potential performance issues?
I'm using Blaze-Persistence and noticed that its offset pagination feature projects the count query as follows( concisely reduced ):
select *, (select count(*) from Entity)
from Entity e inner join ...
0
votes
1
answer
61
views
Spring Data JPA - Programmatically Create JPA Repository Not Saving Data
Creating a JPA repository "on the fly" does not seem to work for saving entities (with or without transaction management). Yet it works fine for retrieving data. No error is thrown. With SQL ...
0
votes
0
answers
13
views
Hibernate duplicates query for non-existing entities with OneToOne relationships
I want to prevent the duplicate SQL queries executed by hibernate, as my underlying relation is a complex view, (although maybe postgresql might cache the result, but still I would vastly prefer if ...
0
votes
2
answers
28
views
global Exception Handler overrules database transaction handler
I am sort of stuck at a particular funny error in a quarkus REST-service that I am currently developing.
My application manages panache entities and I implemented some CRUD operations in a resource ...
-1
votes
0
answers
9
views
How to reference an entity's attribute from a separate method?
There is a query :
String hql = "select concat(p.libelle, '#', rpad(concat('>>>>> ', lower(c.libelle)), "+indentationQte+", '.'), '#', '" + getAccompagnements(d.id) +...
-2
votes
1
answer
53
views
Hibernate forces foreign key to be non-null
I want a Product to have an optional ProductType.
But during schema generation, Hibernate for some reason ignores my definition and creates a non-nullable column for a foreign-key.
We are using ...
0
votes
0
answers
22
views
JPA @Procedure multiple out parameters
Here is my working code:
public interface CandidatRepository extends JpaRepository<Candidat, String> {
@Procedure(procedureName = "garnuche.INSCRIPTION_TEST")
...
1
vote
1
answer
48
views
Why does enum cause type mismatch when saving in postgresql from JPA?
I have a user object defined as such
@Entity
@Table(name = "user_account")
public class User {
public enum Role {
CLIENT,
ADMIN
}
@Id
@GeneratedValue(...
0
votes
0
answers
11
views
How/where can I configure the JPA query used for a nested collection property?
I'm rewording (hopefully simplifying) my previous question as it got no response.
When a Parent Entity contains a List<Child> property, how can I control/configure/override the default Parent ...
0
votes
0
answers
37
views
Workaround for using DetachedCriteria with JPA & Hibernate-6?
In my org, many applications heavily depend on the DetachedCriteria of Hibernate.
The application sends DetachedCriteria to the library which internally uses hibernate sessions and sends the result ...
0
votes
1
answer
23
views
Why Join attribute appending with join column?
I have two entity
@Entity
@Table(name = "Student")
class Student{
@Id
@Column(name = "Id")
private Integer id;
@Column(name = "name")
private String name;
@OneToMany(...
0
votes
1
answer
42
views
Joining Entities by a Range - Hibernate
I have a question regarding Hibernate that's been bothering me for some time.
Consider I have two entities:
@Entity
public class Statement {
@Id
@Column
private int id;
@Column
...
1
vote
0
answers
43
views
Column <name> is of type json but expression is of type smallint[]
There is field of json type in postgres db named data_processing_steps.
It's defined in category entity as
@Type(JsonType.class)
@Column(columnDefinition = "json")
private Set<...
0
votes
1
answer
20
views
How to reduce time taken by createEntityManagerFactory
I'm setting up unit tests for my company application. It's set up to create a new docker container of the database for every test, so each test has a fresh database to work with. However, I get an IO ...
0
votes
0
answers
17
views
record content lost with jooq 18 + spring boot 3.2 + jpa annotations [updated]
I'm working on a small tutorial project that will have both jooq and various spring database implementations. The idea is to demonstrate a core module with nearly everything plus minimal, easily ...