Questions tagged [jpa]

The Jakarta/Java Persistence API (JPA) is a Java specification for accessing, persisting, and managing data between Java objects/classes and a relational database. It is part of the EJB 3.0 specification and is the industry standard approach for Object to Relational Mapping (ORM).

Filter by
Sorted by
Tagged with
0 votes
0 answers
8 views

criteria api : get Last modified record by date

I have two tables with oneToMany association: @Entity @Table(name = "brand") public Class Brand { @Column(name = "name") private String name; @OneToMany(mappedBy = "...
0 votes
0 answers
24 views

Kotlin - convert string to generic type

Here's my function fun <T, U> fetchChildEntity(childEntityName: String?): Specification<T> { return Specification { root: Root<T>, query: CriteriaQuery<*>, builder: ...
  • 2,154
0 votes
0 answers
13 views

In Hibernate, when exactly is lazy loading called? [duplicate]

When you apply fetch = FetchType.LAZY, what cases actually trigger the loading? Surprisingly, I can't find any documentation on this.
0 votes
0 answers
33 views

In JPA, what benefit is there for "save" to return a new persistent instance for the case of updates?

I understand that merge is for updating an existing record, and persist is for inserting a new record. When save is called for the case of update, we return the return value of calling merge. But I ...
0 votes
0 answers
20 views

how to build criteria to use left join with and condition instead of where

I'am using criteria api to build query like this I have tested : List<Predicate> predicates = new ArrayList<>(); Join<Brand, Model> modelJoin = root.join(Brand_.models, JoinType.LEFT)...
0 votes
0 answers
15 views

join two tables using a foreign key and filter results based on a column value in JPA

I have 2 columns SUBMITTER and DEMOGRAPHIC. I want to perform a join using SUBMITTER's primary key SUBMITTER_ID and DEMOGRAPHIC_PARENT_ENTITY_ID which is the foreign key present inside DEMOGRAPHIC. ...
0 votes
0 answers
7 views

OpenCSV annotation disallowed in a JPA Entity Bean

I'd like to add some OpenCSV annotation in a JPA Entity Bean, but JPA rejects the OpenCSV annotation: @CsvBindByName @Caption("TransactionId") @Column(name = "transactionId"...
0 votes
0 answers
9 views

Hibernate returning different object from session cache

public class A { private B b; @NotNull @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "B_ID") public B getB() { return this.b; } public void ...
  • 1,044
-1 votes
0 answers
31 views

Wrong SQL statement join table one to many hibernate JPA

i have two Entitys/Tables and want to Join each other. @Entity @Table(name = "ARTIKEL") public class Artikel{ @Id @GeneratedValue(strategy = GenerationType.AUTO) private ...
0 votes
0 answers
12 views

Can't Inject JPA API after Play 2.8 upgrade in Integration Tests (Scala)

So I am currently upgrading a project to Play 2.8 version, and I've managed to adapt Unit tests and the whole application to run the JPA API as requested in this new version, with Dependency Injection ...
0 votes
0 answers
22 views

JPA repository save() doesn't work on @Service

I'm trying to save a Campaign entity which is in relation OneToOne with entity Card (and Activity has a Card but it doesn't care), when i save the campaign on the class test (on @BeforeAll), the ...
0 votes
0 answers
20 views

HINT_PASS_DISTINCT_THROUGH = false with DISTINCT and ORDER BY returns SQLGrammarException in Postgresql

I'm using Hibernate's JPQL statement with both DISTINCT and ORDER BY expressions on different columns. Before executing the statement I'm setting HINT_PASS_DISTINCT_THROUGH to false, which shouldn't ...
0 votes
1 answer
295 views

Why is JPA / Hibernate slowing down when loading a large amount of data in a Spring Boot application?

When using Spring Data in a RestCall there is a Session in which Hibernate is caching Data. Loading a new Entity inside one RestCall causes Hibernate to caching this Entity while until the RestCall is ...
  • 1,134
0 votes
1 answer
26 views

Update a field in PostgreSQL and generate an event from that to be caught in a Java Application

I'm developing an app about a vote section and need your help. This voting system has a table called Section to control the vote sections (obviously). The table has some fields but 3 are important for ...
1 vote
0 answers
20 views

How to require an attribute to be null if another attribute is not, and require one to be not null if another is not null?

Simply, in one of my entities I want to require an attribute to be null if another attribute is null and reverse. Specifically, I want a timeslot to require an employee if the activity is not null. ...
  • 33
0 votes
0 answers
17 views

Return [ ] instead of item that is inside database Spring boot

I would like to check whether databases contains any data that its quantity is larger than zero and the input and output should be a list. but following code return [ ]. Can I know how to do that? ...
  • 21
1 vote
1 answer
34 views

How to reuse common parts of a long but similar native query in spring boot JPA repositories?

In my Repository interface I have 2 similar aggregate queries which only differs on the group by column, @Query(value = "select table1.a1, sum(table2.b), sum(table2.c) from table2" + " ...
0 votes
1 answer
47 views

Best way to fetch max date using jpa repository

I have a table event CREATE TABLE `event` ( `otherTableId` bigint unsigned NOT NULL, `updateDateTime` datetime NOT NULL, KEY `otherTableId` (`otherTableId`) ) ENGINE=InnoDB DEFAULT CHARSET=...
  • 53
0 votes
0 answers
7 views

JPA criteria projection with dynamic number of joins

I have a query with Criteria which consists of multiple joins of same entity. The amount of joins is dynamic, the code as following: @Entity public class Member { @Id Long id; String name;...
  • 146
0 votes
0 answers
17 views

configuration sessionfactory in hibernate 6

i am using hibernate 6 with spring boot 3 and i have problem to create sessionfactory bean programmicaly now i try to create session factory with Configuration, but spring boot make error for ...
  • 3
-4 votes
0 answers
30 views

I have been learning JDBC , hibernate and ham totally confused....? please check below for full question [closed]

I have been learning JDBC , hibernate and I am totally confused by the the words like entitymanager , sessions and Transaction ? should I remember these ? what are these ? or is there any better ...
0 votes
0 answers
13 views

jpa hibernate rollback on onetomany (Three Models)

I have three model for my jpa which i consider the user @Entity @Data public class User { @Id @GeneratedValue(strategy=GenerationType.AUTO) private Integer id; @NotNull() ...
  • 1
0 votes
0 answers
24 views

Convert db records into JPA code for unit tests?

I have a bunch of DB records I'd like to just convert to java code, using JPA, to use in @DataJpaTest unit tests. I often do this by either using SQL itself, or json or CSV files for certain types of ...
0 votes
1 answer
18 views

Getting 400 bad request when trying to redirect to main page

I want to create a simple crud app for employee management system. When I click on add button in the browser i get redirected to localhost:9090/employees/new, however when I click on submit button ...
0 votes
0 answers
12 views

Is there a way to use custom counting query in Spring JPA with Specification parameter

one of the tables we have for events is a bit large (>900Gb). One of the use cases is to get the last 10 rows with pagination and some filter. Currently, it uses "Specification" instead ...
  • 1,745
0 votes
1 answer
34 views

Getting "org.springframework.beans.factory.UnsatisfiedDependencyException while creating a project using Springboot+OracleDB+JPA

I am trying to work on a POC in Spring Boot to implement CRUD operations on an Oracle DB using JPA repository. The API calls on my controller are working well but when I try to inject JPA repository, ...
0 votes
0 answers
30 views

How to generate Dynamic select and group by clause based on user input and return a List<UserType> in spring jpa?

I have a requirement like : User will pass the List as input, By using the user input I want to build the query dynamically (SELECT and GROUP BY clause) and retrive data from database. For Example : ...
  • 11
0 votes
0 answers
22 views

JPA not removing entity

I'm trying to remove entity but for some reason it doesn't work. I there were similar questions, but they were usually related to cascade removal and @OneToMany relations. This is not the case here. ...
0 votes
0 answers
29 views

Spring Boot JPA Unique Constraint as ID

I'm using Spring Boot JPA. I have two entities. CommunityProfile and Award. These share a many to many relationship, mapped by the award_community_profile table. In this table there is three columns: ...
  • 119
0 votes
0 answers
14 views

Is there a way to create a domain in a Springboot starter?

I'm working on a spring-boot-starter and was wondering if there is a way to instantiate a domain object from an entity/repository after datasourceConfig in implementing application has run? I know I ...
  • 317
0 votes
0 answers
11 views

Getting class not managed exception on Entity class

I have created a project and created two modules inside it as two separate services. Now when I run my first module via main class I get the below error: org.springframework.beans.factory....
0 votes
1 answer
37 views

Required Type - capture of?

I am stuck on an issue that involves generics. I understand the problem, but I do not know how call methods for JpaRepository. For instance, when I call existsById and pass a Long number value, I get ...
  • 521
0 votes
0 answers
11 views

Should @CreationTimestamp make the "created_at" fields of the object being updated after save has been done?

In the @Entity I have a field: @CreationTimestamp @Column(name = "created_at", updatable = false, nullable = false, columnDefinition = "TIMESTAMP") private LocalDateTime ...
  • 3,783
1 vote
1 answer
31 views

Error in spring data query using type. InvalidDataAccessApiUsageException: Parameter value did not match expected type [java.lang.Class (n/a)]

I have a superclass and two subclasses. I want to write query that extracts records of a specific class from a common table. (I use the single table mapping strategy). My request looks like this: @...
  • 23
0 votes
0 answers
8 views

Dashboard Implementation in Spring Boot using JPQL

I have a table named users in mysql database. I need to create some sort of dashboard and fetch the count of the user depending upon their status and type. I have written the query as below. Now i ...
  • 1,253
0 votes
0 answers
11 views

IllegalArgumentException when executing join with SUBSELECT

I have a news entity with relationship to NewsCountries entity. Here is the code: @Table(name = "NEWS") @Where(clause = "EXT_ID IS NOT NULL AND EXT_CODE IS NOT NULL") public class ...
  • 896
0 votes
1 answer
18 views

can do this with JPA / Hibernate using from for fn name [closed]

SELECT col11,col12,col13 FROM table(schema.fn_name(param1,param2,param3)) ORDER BY col11,col12; the query can display other additional field (xyz) as well, although there is no such column. I can do ...
0 votes
0 answers
8 views

Proper Spring Data Join Annotation with Composite Primary Key and Transaction Table

What I have tried and what I want are below.. pom.xml ... <properties> <java.version>17</java.version> </properties> <groupId>org....
  • 113
0 votes
1 answer
13 views

Springboot JPA Transactional Annotation with Isolation property not working

Using isolation level as READ_UNCOMMITTED or READ_COMMITTED, the same set of rows are returned even on updating one of the rows in another transaction. I checked in the pg_stat_activity logs, query is ...
0 votes
0 answers
33 views

Java Spring Error No mapping for GET/POST [closed]

I am having an issue with a test application I am making. I get the same error regardless of the endpoint I try. The annotations above the application class were added after doing some searching. They ...
  • 11
0 votes
0 answers
13 views

How can I initialize an ElementCollection from a native query using JPA API?

I am trying to use a native query to avoid n+1 selects with an eagerly fetched @ElementCollection while limiting the result size at the same time. Assuming the following (simplified) entities: @Entity ...
  • 304
0 votes
0 answers
19 views

Exception Report error in Netbens Thymeleaf

The netbeans project loads perfectly, but when trying to open the view in the browser, it gives the following error: HTTP Status 500 – Internal Server Error Type Exception Report Message Request ...
  • 1
0 votes
1 answer
26 views

Jpa delete does runs but does not actually delete the object from database

I have a user class that has the relationship one-to-many with comments and posts. Each user can have many post and comments. Also each post can have many Comments. The problem is when i try to delete ...
0 votes
0 answers
12 views

ManyToOne Relationship with the same entity

I have an entity @Entity class Employee { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; //Other fields } Every employee has a superVisor, which is ...
1 vote
0 answers
13 views

Spring Boot JPA one to one unidirectional shared primary key is working with CommandLineRunner but the same is not working from REST endpoint

I have two entities. Address and Employee. When I try to persist using CommandLineRunner everything is working as expected but when I try the same from REST endpoint, the data is saved in DB but I am ...
0 votes
0 answers
14 views

Java JPA @ManyToMany relation using mySQL empty join table

I am working on an app that downloads job offers from different online services in JSON then parsing it into my own Offer class and puts parsed data into mySql database. My Offer class has field Set&...
  • 1
0 votes
1 answer
17 views

Existing entities loss their parent after updating the parent

Here is a parent structure of entity classes with one-to-one and one-to-many relationships in a Spring Boot application: @Entity @SuppressWarnings("common-java:DuplicatedBlocks") public ...
  • 2,386
1 vote
0 answers
17 views

mappedBy reference an unknown target entity property java.base@17.0.5/jdk.internal.misc.Unsafe.park(Native Method)

I followed this example to the letter :link but I'm getting this pile of errors .I already tried to change the name of the mapping many to many changing the name of the table but without success User ...
0 votes
0 answers
11 views

Get Filtered Nested Entity

I have two classes User and UserAssociation User has OnetoMany mapping of UserAssociation I'm using Jpa Criteria To Fecth User but when i try to lazy fetch UserAssociation it skips the Filter @Getter @...
0 votes
0 answers
17 views

JPA: Defining an Index using JPA for a field in a JSON column?

I have an Entity I want to define a Unique Index for that is a field of the JSON column. import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.Table; import ...

1
2 3 4 5
1018