I have two JPA-entities: and I tried to write a JPQL query to extract requests that: If the parameter is false then extract all requests with empty hotelBookings and all requests where every booking have parameter jointCheckIn is set to false If a parameter is true then extract all requests that have one or m…
Tag: jpa
How can I build a predicate filtering to where ALL tags in an array exist, joined to a record, using criteriaBuilder?
Here’s an example of the syntax I’m using for another condition (where ANY of the tags appear on the document via a FK). predicates.add(root.join(Document_.tags).in({ pseudocode array of tags })); I’m trying to come up with a similar predicate, but where the Document entity has ALL of the ta…
How do I work out the entity relationships in my game collection database?
I have a game collection application where I want to create seperate lists of games. I am using Spring JPA and Hibernate in the backend and this is what the Entity classes look like right now. I am not sure if this is even the right approach… In the end, I want to create a Spring Boot application where …
Sort collection according to user custom input by single or multiple attributes
I have collection of Item object and the class Item is as follows -> Now, I want to sort according to the user input. User can sort it according to his choice like brand, price or publishedDate and even with the multiple parameters. Like brand and price or price and publishedDate. I have seen Comparator to…
Spring pageable sort on other entity’s nullable attribute
I came across the following problem… I have three entities: and method using Specification for fetching information about Contracts: and now, my application gives the possibility to sort Contract entities by Department name, so there comes Pageable object with sort parameter set to employee.department.n…
Strange exception when mapping two columns in a table to the same column in another table
There are two entities: and when i create repository with custom query the exception is thrown but if i remove the second referencing column from the query the program starts without exceptions. Moreover, if i use standart query method bookRepository.findAll(): all works fine Books: Book{id=3, name=’Tes…
Query on parent’s collection – Hibernate Specification
I have three tables created with Hibernate. Product is the parent while barcodes is a collection end price is a child (one to many) of products. I’m trying to query starting from the child (Price). I was able to query on a string but now i would like to query on the collection s element. how would you w…
One to One relationship mapping JPA SpringBoot implementation error: ids for this class must be manually assigned before calling save()
I am trying to understand the JPA Spring Boot implementation for One-to-One mapping classes and was hoping if anyone could provide me a clear picture. One to One mapping Scenario: Table foo and Table childfoo Foo has the columns foo_id,foo_name, foo_place childfoo has the columnd foo_id(foreignkey of foo tabl…
Spring Data JPA- ignore parameter if it has a null value in between condition
I’m trying to write the following query Now it’s work fine but I want if fromDate is null to bring all data till toDate and if toDate is null to bring all data from selected date in fromDate till current date and if both are null to ignore the condition Answer You can try next pattern
Difference between connecting to a database using DriverManager and SpringBoot(Hibernate)
There are 2 ways to connect to a database when developing Java apps. Using DriverManager Connection conn = DriverManager.getConnection(url, name, password); // execute the query. Using application property file in SpringBoot spring.jpa.hibernate.ddl-auto=none spring.datasource.url=jdbc:mysql://localhost:5432/…