jpql

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

How to make both bidirectional hiberbate entities serialized

两盒软妹~` 提交于 2021-01-28 05:20:18
问题 I have 2 Entities: public class Restaurant { @OneToMany(fetch = FetchType.LAZY, mappedBy = "restaurant") private Set<Vote> votes; } and public class Vote { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "restaurant_id", nullable = false) private Restaurant restaurant; } if I try to get both of them like that @Query("SELECT r FROM Restaurant r JOIN FETCH r.vote ") I get Infinite Recursion with Jackson JSON. So I managed to find a way to handle that: public class Restaurant {

Does @PreUpdate always run when @PrePersist runs?

梦想的初衷 提交于 2021-01-27 20:23:16
问题 I have an Entity like below: @Entity public class Order { @Id private String orderId; @Temporal(TemporalType.TIMESTAMP) @Column(name = "created_at", nullable = false) private Date created; @Temporal(TemporalType.TIMESTAMP) @Column(name = "updated_at", nullable = false) private Date updated; @PrePersist protected void onCreate() { this.created = new Date(); this.updated = this.created; } @PreUpdate protected void onUpdate() { this.updated = new Date(); } } I have to find all the orders that

Find entity by exact matching in collection

牧云@^-^@ 提交于 2021-01-27 05:01:08
问题 I have entity like this: @Getter @Setter @Entity public class Conversation extends AbstractEntity{ @ElementCollection @Column(name = "user_id", nullable = false) @CollectionTable(name = "conversation_user", joinColumns = @JoinColumn(name = "conversation_id", nullable = false)) private List<String> usersIds; } Is possible to find conversation entity by spring's repository by exact matching of user ids? For instance I have these entities: id | user_ids ------------------------------------------

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 @> '

Spring Boot JPA: Passing Multiple Values for the Same Parameter (JPQL)

岁酱吖の 提交于 2020-11-28 02:15:14
问题 I'm using JPQL to write SQL queries in JPA's CurdRepository interface. I was able to write more than one query with named parameters and they work like a charm. However, my application requires that I match an unknown number of strings with more than one column in a table. To my knowledge, in SQL it'd look something like this: SELECT * FROM TABLE WHERE COLUMN_1 LIKE "%string_1%" OR COLUMN_1 LIKE"%string_2%" ... OR COLUMN_2 LIKE "%string_1%" OR COLUMN_2 LIKE "%string_2%" ... ... I tried this