52,181 questions
0
votes
0
answers
57
views
Mapping an entity with an embedded key
There is a class with an EmbeddedId.
@Entity
@Getter
@Setter
@Table(name = "indicator_values")
public class IndicatorValue {
@EmbeddedId
public IndicatorValueId id;
@Column(...
0
votes
0
answers
56
views
"DefaultJpaDialect does not support custom isolation levels" when upgrading to spring batch 5
I am upgrading an app to newest Spring Boot 3, and because of that Spring Batch is upgraded to 5.2.3 (from 4.3.10).
The application did not persist batch states previously, it was using the "map ...
Advice
0
votes
0
replies
17
views
Can JPA persist null-element-containing Byte[] or Character[]?
According to the 2.6. Basic Types, Byte[] and Character[] may be mapped, yet as discouraged.
And then can the array may contain null elements?
-1
votes
0
answers
169
views
EclipseLink Converter autoApply=true not working
I have an entity with an enum class field :
@Entity
public class Trade {
@Id
private Long id;
@Column(name = "kind")
private TradeKind kind;
}
Here the enum ...
-3
votes
1
answer
84
views
Converting from Java model to JPA
I have implemented a class User that represents a User (so far either a Student or a Teacher). What they have in common is that they both have IDs, and some information about the user (this is stored ...
3
votes
0
answers
56
views
Hibernate OptimisticLockException in Java 21 – works fine in Java 17
Title:
Hibernate OptimisticLockException in Java 21 – works fine in Java 17
Body:
I recently upgraded my project from Java 17 → Java 21, and one of my Hibernate test cases started failing with this ...
1
vote
0
answers
83
views
How to pass client location into custom JPA ID generator?
Working on a scalable custom ID generator in JPA. The format I want to achieve is:
<first three letters of country or region> + <year> + <sequence number>
For example: USA2025001
I'm ...
5
votes
1
answer
153
views
Integrating a Jakarta Persistence implementation with modular JavaFX/Maven/JLink app
Quick background information for context: I'm writing a relatively small tool for a small gaming community to download and manage user generated content. It's a modular Java 24 + JavaFX Project done ...
1
vote
2
answers
109
views
Hibernate 6 unidirectional many to one relationship and database cascading deletes
I have an extensive JPA model which exclusively uses unidirectional @ManyToOne relationships from child to parent, for example like this.
public class Child {
@ManyToOne(optional = false)
@...
0
votes
1
answer
65
views
How to implement post remove behavior on a JoinTable using EclipseLink jpa?
Having unidirectional ManyToMany mapping in an entity called A to entity called B on field called files:
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = JOIN_TABLE_NAME)
private List<B> ...
0
votes
0
answers
53
views
Java object DB fields not updated
public void toggleBlacklistPatient(Patient patient, boolean blacklist){
if(patient == null || patient.getId() == null){
return;
}
if(blacklist && !...
2
votes
3
answers
203
views
JPA recursive hierarchy read - StackOverflowError with FetchType.EAGER but LazyInitializationException with FetchType.LAZY
I'm working with these entities:
UserEntity:
@Entity
@Table (name = "users", uniqueConstraints = @UniqueConstraint(columnNames={"name"}))
public class UserEntity {
@Id
@...
1
vote
2
answers
105
views
Out of Memory when deleting comment-classes with childstructure
I use Hibernate for a project. It's a ticket system.
For that I created comments with childcomments.
But every time I want to delete a comment, hibernate escalates and tries to load just EVERYTHING.
...
0
votes
0
answers
63
views
How do I define a bridge table/many-to-many relationship in my schema for use in a Spring JPA BE?
I'm working on a personal project to get better understanding of BE/architecture/how everything ties together, but I'm having trouble finding examples that show the full picture. Right now, I'm ...
-3
votes
3
answers
255
views
How can I generically convert a String value into an instance of a given Comparable type in Java?
I’m trying to implement a generic utility method that takes a String value and a Class<?> type, and returns an instance of that type.
The context: This value represents data from a JPA column, ...
2
votes
2
answers
114
views
Mapping multiple subclasses to same Parent ID in JPA Joined Inheritance
I created the tables Person, PersonExtra, PersonBasic, etc. in my database with the superclass Person and subclasses PersonExtra and PersonBasic.
@Entity
@Table(name = "person")
@Inheritance(...
2
votes
0
answers
86
views
What is the proper way to expose JPA managed entities in Java Entity Models?
Say I have a model with a many to many or many to one relationship. This model would like this:
@Entity
public class A {
// other fields ...
@OneToMany(...)
private List<B> bEntities = ...
2
votes
1
answer
73
views
JPA : how to get benefit of the 2nd level cache after Hibernate changed to prevent select n+1
Situation
Imagine the cacheable JPA Entity :
@Entity
@Table(name = "COUNTRY")
@Cacheable
@Getter
@Setter
public class CountryEntity {
@Id
@Column(name = "CODE")
...
0
votes
0
answers
37
views
Oracle 19c FOR UPDATE SKIP LOCKED still allows same row to be processed by two app instances
I have a JOBS table in Oracle 19c and a method that fetches jobs from the table, sets their status as RUNNING, and then releases the lock by committing the transaction. Basically, I have something ...
0
votes
0
answers
56
views
How to efficiently query data from lists with bundles
I have xId, yId, and zId bundles as a list, and I have to look them up in the DB using Where conditions. Is there a way to look up them most efficiently.
val bundledList = listOf(
listOf(1, 1, 1),
...
2
votes
0
answers
121
views
Hibernate 6 native query on parent class fails with “ORA-17006: Invalid column name”
After upgrading from Hibernate 5 to Hibernate 6, a native query that used to work now fails with an “ORA-17006: Invalid column name” error.
Entity definitions
Base class:
@Entity
@Table(name = "...
1
vote
1
answer
81
views
Duplicate key violation when updating "owner" entity of a one-to-one relation with a new "owned" value
I have two entities, Vehicle and Driver, with a one-to-one relationship. I also have a database constraint to ensure the uniques of a vehicle-to-driver relationship.
@Entity
class Vehicle(
@Id
val ...
5
votes
2
answers
224
views
@EmbeddedId and @MapsId used with foreign key partially appearing in primary key
I'm running a Spring Boot app.
I have these two tables in my database. I fill an example of data that contains these tables.
Table user
Here columns id and century are PKs, and column state_id is a FK ...
1
vote
0
answers
31
views
Spring EntityManager persist vs merge for manual cascading one to many relationship [duplicate]
I have Post and Comment entities with one to many relationship.
@Entity
public class Post{
@Id
private Integer id;
@OneToMany(mappedBy ="post")
private Set<Comment&...
0
votes
1
answer
86
views
Jpa - Join table that contains 2 PK but only one of this two is used
I'm running a Spring Boot app.
I have these two tables in my database.
I fill an example of data that contains these tables.
Table user
Here column id is a PK and column state_id is a FK from table ...
0
votes
0
answers
148
views
HikariCP connections leak with MySQL long-running INSERT queries
I’m facing an issue where INSERT queries on a MySQL table get stuck in “waiting for lock”, and even after innodb_lock_wait_timeout (50s), the connections are not released back to HikariCP, eventually ...
0
votes
0
answers
43
views
How to log information indicating that the camel JpaComponent started
I am using a camel route defined in xml. The route starts from this step:
<camel:route id="jpaRoute" routePolicyRef="startPolicy">
<camel:from uri="jpa://?...
1
vote
1
answer
121
views
@LastModifiedDate is not updated with @ManyToMany relation
In Spring Boot I have an entity:
@Entity
@Table(name = "Product")
@EntityListeners(AuditingEntityListener.class)
public class Product extends BaseEntity {
...
@NotNull
@...
0
votes
1
answer
80
views
Single Save with JPA CascadeType.PERSIST resulting to wrong order of insetion
I have the following scenario:
class A {
@OneToMany(mappedBy = "a", cascade = {CascadeType.PERSIST})
List<B> bsOfA;
@OneToMany(mappedBy = "a", cascade = {CascadeType....
0
votes
0
answers
49
views
PostgreSQL "created_at" null constraint violation when using @ManyToMany in Spring Data JPA
I have the following entity setup in Spring Boot with Spring Data JPA:
@Entity
public class Role extends BaseEntity {
@ManyToMany(fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST, ...
0
votes
0
answers
29
views
Multi data source and Criteria building is not able to find Entity Manager
I have a multi data source configuration in spring boot 3.3.3 application connecting to 2 different datasources. which is working for build in queries. Now on one of the connections, i have to do ...
0
votes
1
answer
67
views
What relationship should be used
I have a table (product) as follows which holds product related data
@Entity
@Table(name = "product")
public class ProductEntity {
@Id
@GeneratedValue(strategy = GenerationType....
0
votes
0
answers
35
views
How to efficiently remove entity in Spring Data JPA ManyToMany relationship (delete query)
Given the Entities
public class Foo extends AbstractFoo {
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "foo_bar",
joinColumns = {@JoinColumn(name = "foo_id&...
1
vote
2
answers
143
views
Doesn't JPA has @Transactional by default?
I have a basic CRUD, when trying to delete using the user email I get
"message": "No EntityManager with actual transaction available for current thread - cannot reliably process 'remove'...
1
vote
1
answer
123
views
How make @JoinColumns conditional?
I have the following scenario:
class AId {
String aId1;
String aId2;
}
@IdClass{AId.class}
class A {
@Id String aId1;
@Id String aId2;
String aType; // possible values are 0,1
}
@IdClass{BId....
0
votes
0
answers
55
views
How could I to create ALIAS on @NamedQuery?
I am trying to create a @NamedQuery that use COUNT and ALIAS(AS) to retrieve informations from a SELECT.
The problem is I don't know how could I to create an ALIAS using @NamedQuery. I was looking for ...
1
vote
2
answers
104
views
How to separate a pure domain object from its JPA implementation in a microservice architecture?
I’m refactoring a microservice and I need to move one of my domain objects into an external shared dependency (library).
Currently, this domain object is annotated with JPA (@Entity, @Id, etc.).
...
2
votes
0
answers
86
views
Hibernate Toools 6.5 Reverse Engineering Does Not Generate JPA Annotations
Eclipse 2025-06, OpenJDK 25, Hibernate Tools 6.5, PostgreSQL Database v17, postgresql-42.7.2.jar driver
I set up Hibernate Configuration and checked Console Configuration Type to JPA (jdk 1.5+). In ...
1
vote
1
answer
127
views
What is the correct approach to use Enums in Database with JPA? [closed]
I am working on a Spring Boot + JPA application, and I am confused about the best practice for persisting enums in the database.
Let’s say I have the following enum in Java:
public enum SellerStatus {
...
0
votes
1
answer
128
views
Spring Batch Cannot change transaction isolation level in the middle of a transaction
After updating to Spring Boot 3.4.3 and consequently to Spring Batch 3.5.5, I started getting an error when starting the Job. Previously, I used Spring Batch 2.6.4 and there were no errors.
Job config:...
0
votes
1
answer
91
views
JPA on Glassfish, persisting an updated entity does not store change to DB
I have an rs with an endpoint method annotated as @Transactional. That method fetches an entity, updates a field on it (to a value different than before) and then persists it. However, after the ...
0
votes
0
answers
26
views
Data JPA Specification query for TEXT[] columntype
I've created CalendarEvent Enity as below:
package com.vissibl.core.domain
import com.vissibl.core.api.calendar.EventStatus
import com.vissibl.core.api.calendar.EventType
import com.vissibl.core.api....
1
vote
1
answer
124
views
Is there a way to have two spring boot jpa entities point to the same table?
I have some micro-services and some functionalities are shared across these micro-services, so with my team we agreed that we needed this functionality moved to a SDK.
I've started the migration of a ...
0
votes
1
answer
68
views
How to properly store the last modified timestamp in Hibernate/JPA?
I want to store the user who made the changes as well as the timestamp when the changes were made.
I have a Quarkus backend with REST endpoints. The REST endpoints receive a REST model, which is then ...
0
votes
1
answer
92
views
Why won't JPA let me save a ByteArray into a column of type bytea? [duplicate]
When I try to save Product to this table (with refImg set to bytes from File.readBytes()), the following error is thrown by Spring,
InvalidDataAccessResourceUsageException: could not execute statement ...
0
votes
1
answer
53
views
Do JPA lifecycle callback methods also apply to subclasses?
Are lifecycle callback methods that are defined in a superclass also invoked when updating a subclass entity?
For example assume I have the following entities
@Entity
public class Animal {
// ...
...
3
votes
0
answers
58
views
How to Batch Update row values in JPA
I'm working with a rather large @Entity class that performs asynchronous validation as users create data via multi-step frontend forms.
The current process performs a batch update:
findAllById();
...
0
votes
0
answers
35
views
Updating user details through a form though update refusal in React
I am trying to update user details on a form. I have created a UpdateForm Component that runs componentDidMount to get a particular user and I also used static getDerivedStateFromProps to pre-populate ...
2
votes
1
answer
154
views
JPA repository method with native query containing '&&' works with Long[] but not Collection<Long>
In one of my Spring Data JPA repositories I have this native query (PostgreSQL):
@Query(value = "SELECT * FROM ballots b WHERE b.companies && :companyIds and b.meeting_id in :meetingIds&...
0
votes
1
answer
69
views
Is there a way to interrupt entity update by throwing exception from @PrePersist and @PreUpdate?
I'm looking into JavaDoc of @javax.persistence.PreUpdate and @javax.persistence.PrePersist and there isn't any notice about whether entity persist or update flow will be interrupted when an exception ...