I have 3 tables book, publisher, author. Here author and publisher can refer to same record in book therefore I decided to make book as relationship parent. However I also want to make it so that if a publisherA is deleted, all the book record related to publisherA also get deleted. same goes for author. I tried using cascade, but
Tag: spring-data-jpa
Why spring-boot-starter-data-jpa 2.5.0 can not init data by the cause “table not found”?
I have 2 projects using the same H2 configurations: The first project used spring-boot-starter-data-jpa 1.5.8.RELEASE which can init data successfully. But the second one used spring-boot-starter-data-jpa 2.5.0 CAN NOT init data: Trace the log I have seen that the init data sql is run before the db structure generated. Spring team! Please help to fix this issue to save time
Understanding JPA sequence generator
I’m using spring data JPA’s sequence generator to assign primary keys to entities. Model contains: The corresponding sequence definition(for SQL Server DB): Since I wanted to start the ids from 100 instead of 1, so I updated the sql script to And then I encountered the problem as mentioned here. I fixed it by the solution mentioned there. This made
Spring boot delete object from database based on a OneToOne relationship
i’ve got an “appointment” entity object(table) AND dates_doctor_available entity build like this AND now i wish from a controller to remove the Database entry based on the “date_time_available_fk” Using “Appointment” object. For example something like where inside service there is a data object access something like this(they are interfaces) where id is the date_time_available_fk number i want to pass(i already
Spring Data JPA: delete OneToMany child without going through the parent
My application has a Project entity that has set of Resource entities like this: The Resource entities may be referenced by several projects, and I’m wondering how to delete a Resource from the database easily without first removing it from the resources list of each parent Project. Trying to delete the resource directly using the repository’s deleteById method results in
Why users are not displayed from the database?
I can’t get a list of users from the database.I am assuming userService.allUsers () = null. But why? I have no idea. Since there are users in the database. Please tell me what is wrong with my code? It does not give me any errors in the logs. AdminController Class UserService ForAdmin.html I do not even understand why nothing is
JPA and Spring Boot : integer from DB (H2) doesn’t get mapped to boolean as expected
I am refactoring part of an Spring Boot 2.3.1 application, in which previous developers have used Integer type (with values 0 or 1) instead of boolean a bit everywhere in the code. But I am noticing something I didn’t expect : I’ve also changed the field type in the entity class, and when loading it from the DB, I get
Is it possibe to map a query with nested select statements to a DTO?
I have a query with nested select There is a DTO Class The method of new packageName.Result(a,b) in the query wont work here because of nested select, so what can be done here? Thanks in advance Answer The JPQL constructor expression is really just syntax sugar, so you could just as well transform the resulting list afterwards. I think this
JPA : Re-use Id generated from a sequence for a new version of the same object having composite PK (ID + VERSION)
I have entity A with composite PK [ id(generated from sequence) + version ]. For a brand new record I want to pick the id from a sequence defined in the DB side. Lets say its created like below Next time, I want a new version of the same Id to be created like below Note : in the second
JPA query to filter before, after and between optional start and end dates
I’d like to write a JPA Repository query that can findBy with two optional query parameters, startDate and endDate: startDate endDate Return null null All null endDate Before End startDate null After Start startDate endDate Between Start and End How can this be implemented concisely? For example, using a single JPA @Query method with a SQL statement that can handle