jpa

Can I create a DeepCopy of an Java Object/Entity with Mapstruct?

丶灬走出姿态 提交于 2021-01-05 05:52:08
问题 I have a JPA entity (but this question is interesting in general) that consists of multiple child classes (aggregation). I need to create a new entry in the DB that is 90% identical to the existing one (a few business values and of course the IDs need to be different). As we need mapstruct for mapping between entity and TO I was thinking "Can mapstruct do this for me?" After Creating a deep copy I could simply update the remaining fields and persist the object. Writing a copy constructor by

Can I create a DeepCopy of an Java Object/Entity with Mapstruct?

半城伤御伤魂 提交于 2021-01-05 05:50:09
问题 I have a JPA entity (but this question is interesting in general) that consists of multiple child classes (aggregation). I need to create a new entry in the DB that is 90% identical to the existing one (a few business values and of course the IDs need to be different). As we need mapstruct for mapping between entity and TO I was thinking "Can mapstruct do this for me?" After Creating a deep copy I could simply update the remaining fields and persist the object. Writing a copy constructor by

Implement JPA Projection with count

删除回忆录丶 提交于 2021-01-04 18:58:09
问题 I want to implement JPA Projection with count. I tried this: @Query(value = "SELECT new org.service.PaymentTransactionsDeclineReasonsDTO( id, count(id) as count, status, error_class, error_message) " + " FROM payment_transactions " + " WHERE terminal_id = :id AND (created_at > :created_at) " + " AND (status != 'approved') " + " GROUP BY error_message " + " ORDER BY count DESC", nativeQuery = true) List<PaymentTransactionsDeclineReasonsDTO> transaction_decline_reasons(@Param("id") Integer

JPA OneToMany column name

爱⌒轻易说出口 提交于 2021-01-03 06:28:05
问题 How to set the column name of the foreign key when setting up a one-to-many relationship in JPA? I would like to change the name of "items_id" to "item_id" @OneToMany private List<Item> items; I tried the following annotations with no success: @JoinColumn(name="item_id") // join table is not created @Column(name="item_id") // no effect 回答1: You want to override the mappings of the default values of the join table, so the @JoinTable annotation is the one to use. You want to override the name

Hibernate custom query containing GROUPBY and HAVING

时间秒杀一切 提交于 2021-01-01 09:55:32
问题 So I have two entities with a one-to-many relationship. A form_collection contains multiple form . The form contains a column version which keeps track of the most current form. form +----+-----------------+---------+--------------------+ | id | description_key | version | form_collection_id | +----+-----------------+---------+--------------------+ | 1 | desc1 | 1 | 1 | +----+-----------------+---------+--------------------+ | 2 | desc1 | 2 | 1 | +----+-----------------+---------+------------

Hibernate custom query containing GROUPBY and HAVING

白昼怎懂夜的黑 提交于 2021-01-01 09:54:08
问题 So I have two entities with a one-to-many relationship. A form_collection contains multiple form . The form contains a column version which keeps track of the most current form. form +----+-----------------+---------+--------------------+ | id | description_key | version | form_collection_id | +----+-----------------+---------+--------------------+ | 1 | desc1 | 1 | 1 | +----+-----------------+---------+--------------------+ | 2 | desc1 | 2 | 1 | +----+-----------------+---------+------------

Hibernate custom query containing GROUPBY and HAVING

你。 提交于 2021-01-01 09:52:50
问题 So I have two entities with a one-to-many relationship. A form_collection contains multiple form . The form contains a column version which keeps track of the most current form. form +----+-----------------+---------+--------------------+ | id | description_key | version | form_collection_id | +----+-----------------+---------+--------------------+ | 1 | desc1 | 1 | 1 | +----+-----------------+---------+--------------------+ | 2 | desc1 | 2 | 1 | +----+-----------------+---------+------------

Hibernate custom query containing GROUPBY and HAVING

旧城冷巷雨未停 提交于 2021-01-01 09:52:45
问题 So I have two entities with a one-to-many relationship. A form_collection contains multiple form . The form contains a column version which keeps track of the most current form. form +----+-----------------+---------+--------------------+ | id | description_key | version | form_collection_id | +----+-----------------+---------+--------------------+ | 1 | desc1 | 1 | 1 | +----+-----------------+---------+--------------------+ | 2 | desc1 | 2 | 1 | +----+-----------------+---------+------------

How to convert PSQLs ::json @> ::json to a jpa/jpql-predicate

北战南征 提交于 2020-12-31 06:21:59
问题 Say i have a db-table looking like this: CREATE TABLE myTable( id BIGINT, date TIMESTAMP, user_ids JSONB ); user_ids are a JSONB-ARRAY Let a record of this table look like this: { "id":13, "date":"2019-01-25 11:03:57", "user_ids":[25, 661, 88] }; I need to query all records where user_ids contain 25. In SQL i can achieve it with the following select-statement: SELECT * FROM myTable where user_ids::jsonb @> '[25]'::jsonb; Now i need to write a JPA-Predicate that renders "user_ids::jsonb @> '

How to convert PSQLs ::json @> ::json to a jpa/jpql-predicate

岁酱吖の 提交于 2020-12-31 06:20:16
问题 Say i have a db-table looking like this: CREATE TABLE myTable( id BIGINT, date TIMESTAMP, user_ids JSONB ); user_ids are a JSONB-ARRAY Let a record of this table look like this: { "id":13, "date":"2019-01-25 11:03:57", "user_ids":[25, 661, 88] }; I need to query all records where user_ids contain 25. In SQL i can achieve it with the following select-statement: SELECT * FROM myTable where user_ids::jsonb @> '[25]'::jsonb; Now i need to write a JPA-Predicate that renders "user_ids::jsonb @> '