I have some troubles with Spring JPA relationships. I have two entities: Gift and Candy. And I want user to be able to select available candy and add it to gift. How can I do that using spring jpa? I’ve already tried ‘one to many’ relationship with gift as owning side, and I got “null …
Tag: hibernate
Mapping one to one relationships in Spring Boot
I am trying to map a User with a certain Table in a one to one relationship. This here is my code, id appreciate if u take a look at it: User class: The Table class: Answer You don’t mapped parent entity with child entity properly.In parent table object of CTable is currenTable and you mapped by with ta…
cannot install hibernate(5.6.0) with intellij(m1chip silicon) in java
I try to run hibernate 5.6.0 in java 16 and I am programming with intellij 2021.2 for apple sillicon. When I run it I get this error: My hibernate.cfg.xml is in source root:source tree Answer Always include the resource files in the separate resources directory. As by default, Maven (and so IDE as well) will …
How to access a child element in a query using jpa and hibernate – SpringBoot
I would like to know how to query some child objects using their name as a parameter in Spring boot. Let’s say I have a class parent with a one-to-many relationship with the child. The child has a parameter called name. So I would like to query using like “%name%” so the query would return m…
Showing a specific JSON response for my GET endpoint
I have a many-to-many relationship between Department and Employee I have already done a mapping for the GET endpoint which returns a list of departments that contain Employees, this is the request: http://localhost:8080/api/departments/1/employees, and this is the response I get: This is the code that gets t…
How can I batch the audit table inserts using the Hibernate Envers ValidityAuditStrategy
I’m using Hibernate envers for auditing, and most of my tables are performing batch inserts just fine. However, on one of my entities I have an audited collection, which seems like it doesnt want to batch. MyEntity: (Not sure if this is important, Im using postgresql). In the logs I see 1000s of these s…
Getting error : org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: javax/validation/ValidatorFactory
I have a project Webservice with Hibernate in Eclipse (Tomcat v10.0 et java JDK 8). When I run, I got this error: ” Servlet.service() for servlet [Jersey Web Application] in context with path [/musichall] threw exception [org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: ja…
Cannot generate JPA Hibernate Metamodel classes in IntelliJ IDEA
In my Java project, I get “java: cannot find symbol” errors pointing Metamodel classes e.g. Company_. So, first I checked my-projecttargetgenerated-sourcesannotations and see that it is empty. Then, after several search on the web and SO, I see that the necessary settings seems to be ok and this i…
How to choose fields for auditing with Hibernate Envers?
I’m using Hibernate Envers in Spring Boot application with Spring Data. For example, I have a base class And class I need to audit only actions that were done and the timestamp of them. For example, when I create new Entity or update existing Entity object, I want auditing table to contain the following…
testEntityManager.persistFlushFind() giving error “detached entity passed to persist”
I was trying to test h2 Repository with spring-boot-testing .Below is the Testing code is used.: In the above code I am facing this “detached entity passed to persist”. “testEntityManager.persistFlushFind(new Product(1,”A”,”dec”,false))” is giving below error: P…