I’m using SpringBoot with JPA and Hibernate. I have two entities: Book and Author. A Book can have multiple Authors. So I need a OneToMany relationship. Into the Author table, my idea is to use a composite key (the book_id and one internal field for example field_a) I implemented these classes: When I try to execute my project (I’m using
Tag: hibernate
JPA Criteria builder for dynamic query
I have to write a method where I pass it some arguments and depending on which arguments are empty it modifies the query I need to execute at the end. E.g. if I want to select from a table Customer that has an ID, name, surname and address the starting query would be SELECT * FROM Customer WHERE ID=myId AND
1:n disable constraints for the n-side?
The Problem I have a 1:n relation, but the n side shouldnt rely on constraints. So i actually wanna insert a EntityPojo via its future id, when its not saved yet ( Lets ignore that its a bad practice ). This looks kinda like this. Cascading is not possible here, i only have its future ID, not a reference to
How to create hibernate request with localdate
I have a user who has an expiration date (dateTime), I need to display all users who have not expired yet. Tried different options with DATA (), or as an example – but it doesn’t output anything. But when asked in MySQL – SELECT * FROM user where user.date> NOW () displays everything as it should. Tell me how to
Detached entity passed to persist java spring
So i have a big error when trying to do an update method in my spring application ,the problem is regarding to the Caracter class as thats the one the seems to generate it. When i set my stuff in main and try to update an Anime object in the database the Caracter class gives me the errors presented below
Spring Boot URL mapping not working when files are present in multiple packages
I tried making a simple REST API using Spring Boot. I have put the classes in separate packages. In this case, the URL mapping is not working (checked using Postman), whereas its working fine if I put them all in the same package as that of the main class. “”” Hierarchy of the packages : com.example.ProductCRUD |—–ProductCrudApplication.java (main) com.example.ProductCRUD.Controller |—–ProductController.java(controller)
Cant run my spring application on ubuntu with jdk11
Pls, help. Can’t run my application on ubuntu 18.04.5 Java version: openjdk 11.0.10 2021-01-19 Apache Maven 3.6.0 Maven home: /usr/share/maven Java version: 11.0.10, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64 Default locale: en_US, platform encoding: UTF-8 OS name: “linux”, version: “5.4.0-66-generic”, arch: “amd64”, family: “unix” There is app output: pom.xml: UserService.java RegistarionCotroller.java WebSecurityConfig.java Answer When initializing the WebSecurityConfig, Spring Container will attempt to
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast or BeanUtils.copyProperties not working
am new to JPA and springboot unable to get the api response when am using @Query param(I try achieve the inner join) Repositoty class: Service class: am getting the ” [Ljava.lang.Object; cannot be cast ” exception after that I have changed to as below: service class foreach added the Object but for the above code am getting null values BeanUtils.copyProperties
Error accessing field by reflection for persistent property [model.Credentials#email] on @EmbeddedID
I’ve been experiencing problems implementing the Authorities on my spring boot application, and after digging a little I realised that maybe the association between my Credentials and Authorities tables, was wrong. In fact it come to my attention that Spring allowed every type of user, (regardless their authority) to access ever method, even the ones I though have been secured.
Jpa unidirectional relation in the parent entity
I want to make unidirectional relation in the parent entity, Child entities have FK from the parent entity. The Name table has FK from the person table. But I just want to define the relation in person entity only. I used @JoinColumn for mapping and set name as id from the person table In the next example, I have one