-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support filtering by named queries in REST Data with Panache extension
After #29212 (filter by entity fields) is supported, we can now use namedQueries when filtering. With these changes, you can specify a named query to filter when listing the entities. For example, having the following named query in your entity: ```java @entity @NamedQuery(name = "Person.containsInName", query = "from Person where name like CONCAT('%', CONCAT(:name, '%'))") public class Person extends PanacheEntity { String name; } ``` In this example, we have added a named query to list all the persons that contains some text in the `name` field. Next, we can set a query param `namedQuery` when listing the entities using the generated resource with the name of the named query that we want to use, for example, calling `http://localhost:8080/people?namedQuery=#Person.containsInName&name=ter` would return all the persons which name contains the text "ter".
- Loading branch information
Showing
8 changed files
with
88 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
...ment/src/test/java/io/quarkus/hibernate/orm/rest/data/panache/deployment/entity/Item.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package io.quarkus.hibernate.orm.rest.data.panache.deployment.entity; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.NamedQuery; | ||
|
||
@Entity | ||
@NamedQuery(name = "Item.containsInName", query = "from Item where name like CONCAT('%', CONCAT(:name, '%'))") | ||
public class Item extends AbstractItem<Long> { | ||
|
||
} |
2 changes: 2 additions & 0 deletions
2
.../src/test/java/io/quarkus/hibernate/orm/rest/data/panache/deployment/repository/Item.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package io.quarkus.hibernate.orm.rest.data.panache.deployment.repository; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.NamedQuery; | ||
|
||
@Entity | ||
@NamedQuery(name = "Item.containsInName", query = "from Item where name like CONCAT('%', CONCAT(:name, '%'))") | ||
public class Item extends AbstractItem<Long> { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
...src/test/java/io/quarkus/hibernate/reactive/rest/data/panache/deployment/entity/Item.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package io.quarkus.hibernate.reactive.rest.data.panache.deployment.entity; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.NamedQuery; | ||
|
||
@Entity | ||
@NamedQuery(name = "Item.containsInName", query = "from Item where name like CONCAT('%', CONCAT(:name, '%'))") | ||
public class Item extends AbstractItem<Long> { | ||
|
||
} |
2 changes: 2 additions & 0 deletions
2
...test/java/io/quarkus/hibernate/reactive/rest/data/panache/deployment/repository/Item.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package io.quarkus.hibernate.reactive.rest.data.panache.deployment.repository; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.NamedQuery; | ||
|
||
@Entity | ||
@NamedQuery(name = "Item.containsInName", query = "from Item where name like CONCAT('%', CONCAT(:name, '%'))") | ||
public class Item extends AbstractItem<Long> { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters