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.
20,250
questions with no upvoted or accepted answers
12
votes
2
answers
2k
views
QueryException: ResultTransformer is not allowed for 'select new' queries
I have the following SpringData Repository Query:
@Query("SELECT new com.mypackage.MobileCaseList(c.ident, concat(c.subtype, ' - ', c.contactName), c.type, coalesce(c.updateTimestamp,c....
12
votes
0
answers
4k
views
Hibernate entity filters with Spring data repositories
I'm attempting to use Hibernate 4's Entity level @Filter's with Spring data repositories inside of a Spring Boot project. My end goal is to implement a generic soft delete with something a bit more ...
11
votes
0
answers
2k
views
JpaTransactionManager transactions not used by Hibernate Session
I am working on a project that is using Spring framework (4.3.3.RELEASE) and Hibernate (5.2.3.Final) and I am starting to move to using Spring Data JPA.
I have just migrated the ...
11
votes
1
answer
3k
views
How to map native sql results to oneToMany field with SqlResultSetMapping in JPA
For example, say I have the following database tables
Building
-----------
id
name
and
Room
-----------
id
roomNo
buildingId
the Building Java class will look something like
@Entity
public class ...
11
votes
0
answers
2k
views
JPA 2.1 NamedSubgraph in Hibernate ignoring nested subgraphs
I'm using Hibernate 4.3.8.FINAL and have the following model where a Department has many Employees, and an Employee can be a Manager. Manager has a set of Foo which can be either Foo or Bar.
The ...
11
votes
1
answer
13k
views
Passing a list of values to a stored procedure using JPA 2.1 / Hibernate 4
I have a stored procedure that takes in a list of strings (and follows limitations on stored procedures, according to Hibernate docs):
PROCEDURE count_active_esc(p_count OUT NUMBER, p_codes IN ...
10
votes
0
answers
5k
views
How to emulate "ON CONFLICT" PostgreSQL statement using JPQL
I need to convert PostgreSQL native queries to JPQL. How the following two SQL statements can be translated:
INSERT INTO my_table (id, some_data) VALUES (?1,?2) ON CONFLICT (id) DO NOTHING;
INSERT ...
10
votes
2
answers
1k
views
Unknown entity with Hibernate upgraded to 5.2.3 and above
As soon as I upgrade to Hibernate 5.2.3 or above, Gradle isn't able to find my Entity Classes anymore:
Caused by: java.lang.IllegalArgumentException: Unknown entity: data.model.User
at org....
10
votes
2
answers
7k
views
JPA with Hibernate 5: programmatically create EntityManagerFactory
This question is specifically about programmatically creating a JPA EntityManagerFactory backed by Hibernate 5, meaning without configuration xml files and without using Spring. Also, this question ...
10
votes
1
answer
5k
views
JPA: How to set MySQL session variables?
I need to set a mysql session variable for my application to work with a MariaDB Galera Cluster as expected. The SQL call is: SET SESSION wsrep_sync_wait = 1. It shall be set at all times when the ...
10
votes
1
answer
4k
views
How do I construct a inverse join for a unidirectional relationship?
I guess this is easy, but I can't figure it out.
If I have entities Foo and Bar:
@Entity
class Foo{
@OneToMany
List<Bar> bars;
}
@Entity
class Bar{
@Column
int data;
}
and if I ...
10
votes
2
answers
773
views
JPQL Constructor Expressions, how to eagerly fetch the main entity in 'select new'
The original query I have is somewhat complex, but what I'm trying to do is obtain the entity AlertCondition plus some additional fields.
+ " SELECT new org.rhq.core.domain.alert.composite....
10
votes
2
answers
841
views
Can Hibernate orphanRemoval work with unique constraints?
I have 2 entities: Role and Privilege. One role has many privileges. The entities look like this:
@Entity
public class Role {
private Integer id;
private String code;
@OneToMany(mappedBy =...
9
votes
1
answer
5k
views
Unknown wrap conversion requested after migrating to spring boot 3
I am getting below exception for a jpa query
org.springframework.orm.jpa.JpaSystemException: Unknown wrap conversion requested: java.util.ArrayList to java.lang.string: 'org.hibernate.type.descriptor....
9
votes
1
answer
9k
views
How to LOCK TABLE ... do stuff ... UNLOCK TABLE with Spring Boot?
The idea is basically to extend some Repositories with custom functionality. So I got this setup, which DOES work!
@MappedSuperclass
abstract class MyBaseEntity {
@Id
@GeneratedValue(strategy ...