spring-data-jpa

One to Many Relationship in spring boot REST Api

隐身守侯 提交于 2021-01-29 10:32:13
问题 I am using spring boot to create a REST API. In this API, I have a One to Many relationship between check-in and Guests . I created a controller for check-in and use that save function of spring JPA. The save method is updating both checkin and guest tables but for the guest table, the check-in foreign key in the guests table is not getting added instead showing as null. Please someone help me. I need to create both guests and checkin simultaneously. Check-in Model @Data @Entity public class

How do I transform a data table column from cumulative to difference when reading CSV into spring boot application?

假如想象 提交于 2021-01-29 10:17:43
问题 I have data in a table like date | city | Cumulative total --------------------------------- 1/1/2020 | NYC | 10 1/2/2020 | NYC | 15 1/3/2020 | NYC | 31 1/4/2020 | NYC | 36 1/5/2020 | NYC | 55 . . // more data for NYC continued . 1/1/2020 | BER | 1 1/2/2020 | BER | 5 1/3/2020 | BER | 13 1/4/2020 | BER | 42 1/5/2020 | BER | 45 . . // more data for BER continued . I want this data to not hold the cumulative , but rather hold the difference . Basically I want to subtract the next day from the

“Autogenerated PK as Id” and “Autogenerated UUIDs as String” in a single Entity Spring Data JPA

随声附和 提交于 2021-01-29 09:56:38
问题 My question is an extension to this, this and my own previous question. After loads of other readings too, I have the following in my Entity: @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id") private Long id; @Column(name = "useruuid") @GenericGenerator(name = "uuid", strategy = "uuid4") private String useruuid; Question 1: Are above declarations valid? @Id is for sure yes as we all know it. The question is more focussed on @GenericGenerator(name = "uuid", strategy

JPA Projection with custom collection property

狂风中的少年 提交于 2021-01-29 09:47:19
问题 We are using Spring Data and trying to create a custom query with a subquery, results projection have an array and other properties, our problem is with the subquery array. public interface ProfesionalRepository extends JpaRepository<Profesional, Long> { @Query("SELECT p.id as idProfesional, " + " p.name as name, " + " p.surname as surname, " + " (SELECT a.descripcionIlt FROM Ausencia a WHERE a.profesional.id = p.id) as exclusionesCenso " + " FROM Profesional p ") List

Saving entity with @IdClass produces empty row

别来无恙 提交于 2021-01-29 09:40:02
问题 I'd like to save rows in a simple table that contains the ids of two other entities. After some tries, I arrived at the following configuration. Spring Boot now correctly creates the table, with column names task_run_id and project_id . But when I call repo.save(participant) a row is created but both columns contain 0, instead of the required ids. No error is thrown. What am I doing wrong? Also if there there are some declarations that are unnecessary to achieve a simple save and later query,

Spring data JPA - Dynamic SQL Execution

巧了我就是萌 提交于 2021-01-29 09:17:00
问题 I want to Execute the SQL , which will be constructed completely at runtime and it can be querying any tables in the schema. Something like @Repository public interface BaseRepository extends JpaRepository<Object, Integer> { @Query(":dynamicSQL") List<Object> dynamicExecution(@Param("dynamicSQL") String dynamicSQL); } Please suggest how this can be implemented 回答1: JpaRepository is not designed to be used like this. If you want to execute dynamic SQL query then use EntityManager. This is bad

Why am I getting an internal server error?

可紊 提交于 2021-01-29 09:13:39
问题 I'm creating a REST web service with Spring, but I'm getting a internal server error and don't understand why. I have a List of DoenteIdentidade's, this is the structure of the DoenteIdentidade { "id": 1, "nome": "Highway Ergonomic", "dataNasc": "2020-01-10", "altura": 31098, "morada": "moratorium pixel withdrawal", "codPost": "Mississippi embrace Developer", "freguesia": "synthesize Idaho compress", "nif": 49379, "medFam": "Poland", "sexo": "Masculino", "telef": 3142, "telef2": 89576, "docId

Spring Boot @ManyToOne only Id @JsonProperty

徘徊边缘 提交于 2021-01-29 09:00:21
问题 help me find JSON property annotation who give me choose an entity property to JSON serialization. I need only one. I code like that: @Entity @Table(name = "pages") public class Page { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id") private Long id; @Column(name = "name") private String name; @JsonIgnoreProperties(value = {"name", "description", "pages"}) // it's working, but I want to simplify, I need only project id property to JSON @ManyToOne(fetch = FetchType

Jpa repository and JsonIgnoreProperties return the same object differently in getOne() and in findAll() methods

牧云@^-^@ 提交于 2021-01-29 07:06:51
问题 Brief background I have two methods in an API created on Spring Boot to retrieve data from a mySQL database (via Hibernate and JpaRepository). There is a method that returns all the ocurrences in a table called test , and another one that returns the test corresponding to the id passed as a parameter in the GET call. Both API entry points (by means of the services and repositories) end up calling two JpaRepository methods ( findAll() and getOne() respectively). Problem description The problem

After upgrade from Spring Boot 1.5 to 2.1 we get Target bean of type com.sun.proxy.$Proxy is not of type of the persistent entity

牧云@^-^@ 提交于 2021-01-29 06:54:21
问题 We upgraded from Spring Boot 1.5.13.RELEASE to 2.1.3.RELEASE and now a POST to Spring Data Rest with a projection is failing with this error: java.lang.IllegalArgumentException: Target bean of type com.sun.proxy.$Proxy313 is not of type of the persistent entity (com.*.*.*.BankAccount)!: com.sun.proxy.$Proxy313 This looks very similar to the old ticket: https://jira.spring.io/si/jira.issueviews:issue-html/DATAREST-1213/DATAREST-1213.html The JUnit test passes: @Test public void