Suppose I have the following table called Seasons: … start_month end_month … 2 6 … 3 4 … … … I need to write a query which, for a given list of months, returns all the Seasons that satisfy the condition where at least 1 month in the list is: start_month <= month <= end_month. I’ve written this query as
Tag: hibernate
org.springframework.orm.jpa.JpaSystemException: Don’t change the reference to a collection with delete-orphan enabled
i’m using spring data jpa. when i want to clone an entity with one to many relation, i set the purchaseOrder id =null, and each items id = null, but get the follw exception here is purchaseOrder entity and items entity can any one help with this? Answer No need to reassociate items and purchaseOrder , just clear all relationships,
select new (JPQL Constructor Expression) in jpa/hibernate causes “lazy” loading for each row
Recently I found no obvious behaviour when using ‘select new/constructor expression’ in jpa/hibernate. It uses kind of lazy loading for each entity in each row in result set what is not efficient. Test example First case we issue a query using select new technique: This issues one query to fetch only ids of e1 and e2 and then more queries
Error while querying tables using hibernate
I am trying to query a table called student in MySQL. This is the structure: Here is the java code which I use to query: This is the error message: Here is the image of the referenced libraries: Insertion into table is working correctly. Only querying isn’t. What is the error here? Please comment if extra information is needed. UPDATE:
Saving entity with Spring JPA Repository resets enum ttype value
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
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
Deleting an entity with one to one relation
My two entities have one to one relation I tried to delete my user entity by this method PasswordResetTokenRepository class which method I called in my service method, for deleting user I used regular hibernate method deleteById(Long id) But when I try to delete by this method I got this error: not-null property references a null or transient value :
Use H2 as test DB in JUnit5
I’m developing an app in Spring Boot. I use a PostreSQL DB for production, and I want my JUnit 5 tests to run on a H2 memory DB. Problem is, after some configuration, the tests still don’t seem to run on the in-memory db: I can access entities from the prod db (a saved entity doesn’t persist in the prod
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
Hibernate 5 and JPA: select table without his children but maintain persistence on save
I have two models: Ordine and DettaglioOrdine. I would like that, when I save an object of type “Ordine”, hibernate also save his child “DettaglioOrdine” (and this works). But, if I do a select query, the query is very very slow because hibernate retrieve also DettaglioOrdine. So, I would like the “Ordine” object without “DettaglioOrdine” object. “Ordine” model: DettaglioOrdine Model: