I have an TimelineEntity entity, that uses HoTimelineType enum with custom integer value. That custom integer value is stored in the database. Implemented via Using @PostLoad and @PrePersist Annotations Sprint JPA Repository is used to save and get entities. Here is the issue: When the newTE entity is saved, prePersist is invoked, and inside this method, the hoTimelineType is null
Tag: spring-data-jpa
Spring Data Jpa: persisting child entities from parent entity does not update child identity
Environment: OS: Ubuntu 20.04 LTS Java: OpenJDK 17.0.3 Spring Boot: 2.6.7 MySQL: 8.0.29 Is it normal for Spring Data Jpa (or Jpa in general) to NOT update child identity attributes when the child is persisted (saved) via the parent entity repository? Consider this: When I call someClassFunction() I get: The database assigned id is NOT available to me immediately. I
How to retrieve ONE column from another table with Foreign key using Hibernate / JPA
I would like to use the Foreign key “MODEL_ID” to retrieve just one column “MODEL_NAME” from the TT_CARS table, I tried the following code, that works but it returns the whole CARS object. Also I tried the code below, its also not working Is there other way to retieve just the column (MODEL_NAME) using hibernate and JPA?? remarks: The modelName
Working with multiple parameters in CriteriaBuilder
I have a need to use JpaSpecificationExecutor. Initially, I assumed that one parameter would be given as input and I would process it like this: CarRepository : However, I need to be able to work with: And in response to me came all the options for suitable machines. For example input: At the output, I want to get all the
how do i save a new student that contains entities, but don’t create these entities because they already exist in the database?
I want to save a student and a student has a TargetAudience object as an attribute. These target audiences are allready hardcoded in my database. (targetaudience = campus + major). Now when i post like this: it doesnt work because everythime it creates a new object for the campus and because i use name as a primary key it throws
How can I use more then one param in a spring boot rest Controller?
I want to achive the follwing URL to access my data with 2 params: http://localhost:8080/contactnote?entryDate=2022-02-01?contactType=T Both mappings with a single param is working: But when I try to combine them with two params it wont work, not one of them is usable. My reposiitory looks like this: Answer the URL you entered is invalid, double ?, you have to use
JPA performance – SELECT DISTINCT and/or Java Set
I have a Spring Boot application with a JpaRepository. I am trying right now to obtain all the unique values for a certain field in my db. Let’s suppose I have an object Foo with an Integer PK id and a non-unique Integer field bar. I want to get all the unique values for bar and I’m wondering which query
How to map a table in Spring Data JPA that has 2 columns referencing the same table
I have a table that has 2 fields (pseudonymProfile and realProfile) that both join to the same table. When I try to do the mapping as shown below, I run into an error because the 2 fields use the same name (profile_id) in their @JoinColumn annotation. I’m under the impression that when defining a join column, I need to specify
Combine JPA Query annotation with Oracle sample method
i am trying to pass a parameter into a JPA query Example code But i get an error because of the sample(:percentile). If i just hardcode a number in there it works but not with a param. Is there a way to escape the brackets or something similar? Thx Answer The error is on the following part Unfortunately it does
java.lang.StackOverflowError: null [Spring Boot, Hibernate]
I have two classes User.java and Address.java and there is a one-to-one bi-directional mapping between them. But when I try to get the address using the User class I get an “java.lang.StackOverflowError: null” exception. The same thing happens when I try to get the User from the Address class. User.java Address.java MainController.java I am using the test() function to put