Skip to content
Advertisement

Tag: hibernate

Check if any value in list satisfies a condition

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

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:

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

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:

Advertisement