-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Hibernate ORM Rest Data with Panache quickstart
The Quarkus Hibernate ORM Rest Data with Panache was promoted to Stable in quarkusio/quarkus#28569, so let's add a quickstart for it. This quickstart is based on the code in the guide: https://quarkus.io/guides/rest-data-panache Relates quarkusio/quarkus#29555
- Loading branch information
Showing
26 changed files
with
1,463 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
* | ||
!target/*-runner | ||
!target/*-runner.jar | ||
!target/lib/* | ||
!target/quarkus-app/ |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Eclipse | ||
.project | ||
.classpath | ||
.settings/ | ||
bin/ | ||
|
||
# IntelliJ | ||
.idea | ||
*.ipr | ||
*.iml | ||
*.iws | ||
|
||
# NetBeans | ||
nb-configuration.xml | ||
|
||
# Visual Studio Code | ||
.vscode | ||
|
||
# OSX | ||
.DS_Store | ||
|
||
# Vim | ||
*.swp | ||
*.swo | ||
|
||
# patch | ||
*.orig | ||
*.rej | ||
|
||
# Maven | ||
target/ | ||
pom.xml.tag | ||
pom.xml.releaseBackup | ||
pom.xml.versionsBackup | ||
release.properties |
Binary file added
BIN
+58.5 KB
hibernate-orm-rest-data-panache-quickstart/.mvn/wrapper/maven-wrapper.jar
Binary file not shown.
18 changes: 18 additions & 0 deletions
18
hibernate-orm-rest-data-panache-quickstart/.mvn/wrapper/maven-wrapper.properties
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip | ||
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar |
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 |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# Quarkus demo: Hibernate ORM REST Data with Panache | ||
|
||
This is an example that illustrates how we can use the Hibernate ORM REST Data with Panache extension to automatically generate the CRUD endpoints for your entities and repositories. | ||
|
||
Under the hood this is using: | ||
- RESTEasy Reactive to expose the REST endpoints | ||
- Hibernate ORM to perform the CRUD operations on the database | ||
- A PostgreSQL database; see below to run one via Docker | ||
- ArC, the CDI inspired dependency injection tool with zero overhead | ||
|
||
## Requirements | ||
|
||
To compile and run this demo you will need: | ||
|
||
- JDK 11+ | ||
- GraalVM | ||
|
||
In addition, you will need either a PostgreSQL database, or Docker to run one. | ||
|
||
### Configuring GraalVM and JDK 11+ | ||
|
||
Make sure that both the `GRAALVM_HOME` and `JAVA_HOME` environment variables have | ||
been set, and that a JDK 11+ `java` command is on the path. | ||
|
||
See the [Building a Native Executable guide](https://quarkus.io/guides/building-native-image) | ||
for help setting up your environment. | ||
|
||
## Building the demo | ||
|
||
Launch the Maven build on the checked out sources of this demo: | ||
|
||
> ./mvnw package | ||
## Running the demo | ||
|
||
### Live coding with Quarkus | ||
|
||
The Maven Quarkus plugin provides a development mode that supports | ||
live coding. To try this out: | ||
|
||
> ./mvnw quarkus:dev | ||
In this mode you can make changes to the code and have the changes immediately applied, by just refreshing your browser. | ||
|
||
Hot reload works even when modifying your JPA entities. | ||
Try it! Even the database schema will be updated on the fly. | ||
|
||
### Run Quarkus in JVM mode | ||
|
||
When you're done iterating in developer mode, you can run the application as a | ||
conventional jar file. | ||
|
||
First compile it: | ||
|
||
> ./mvnw package | ||
Next we need to make sure you have a PostgreSQL instance running (Quarkus automatically starts one for dev and test mode). To set up a PostgreSQL database with Docker: | ||
|
||
> docker run --rm=true --name quarkus_test -e POSTGRES_USER=quarkus_test -e POSTGRES_PASSWORD=quarkus_test -e POSTGRES_DB=quarkus_test -p 5432:5432 postgres:13.3 | ||
Connection properties for the Agroal datasource are defined in the standard Quarkus configuration file, | ||
`src/main/resources/application.properties`. | ||
|
||
Then run it: | ||
|
||
> java -jar ./target/quarkus-app/quarkus-run.jar | ||
Have a look at how fast it boots. | ||
Or measure total native memory consumption... | ||
|
||
### Run Quarkus as a native application | ||
|
||
You can also create a native executable from this application without making any | ||
source code changes. A native executable removes the dependency on the JVM: | ||
everything needed to run the application on the target platform is included in | ||
the executable, allowing the application to run with minimal resource overhead. | ||
|
||
Compiling a native executable takes a bit longer, as GraalVM performs additional | ||
steps to remove unnecessary codepaths. Use the `native` profile to compile a | ||
native executable: | ||
|
||
> ./mvnw package -Dnative | ||
After getting a cup of coffee, you'll be able to run this binary directly: | ||
|
||
> ./target/hibernate-orm-rest-data-panache-quickstart-1.0.0-SNAPSHOT-runner | ||
Please brace yourself: don't choke on that fresh cup of coffee you just got. | ||
|
||
Now observe the time it took to boot, and remember: that time was mostly spent to generate the tables in your database and import the initial data. | ||
|
||
Next, maybe you're ready to measure how much memory this service is consuming. | ||
|
||
N.B. This implies all dependencies have been compiled to native; | ||
that's a whole lot of stuff: from the bytecode enhancements that Hibernate ORM | ||
applies to your entities, to the lower level essential components such as the PostgreSQL JDBC driver, the Undertow webserver. | ||
|
||
## See the demo in your browser | ||
|
||
Navigate to: | ||
|
||
<http://localhost:8080/index.html> | ||
|
||
Have fun, and join the team of contributors! | ||
|
||
## More Information | ||
|
||
To find more features, please go to [the Hibernate ORM REST Data with Panache guide](https://quarkus.io/guides/rest-data-panache). |
Oops, something went wrong.