Skip to content

[WFLY-21081] Add a Jakarta Data quickstart - #1110

Open
bstansberry wants to merge 3 commits into
wildfly:mainfrom
bstansberry:WFLY-21081
Open

bstansberry wants to merge 3 commits into
wildfly:mainfrom
bstansberry:WFLY-21081

Conversation

@bstansberry

@bstansberry bstansberry commented Nov 30, 2025 •

Copy link
Copy Markdown
Contributor

https://issues.redhat.com/browse/WFLY-21081

This is basically the todo-backend quickstart but with a different persistence layer. The todo-backend QS seems like a perfectly good one for showing a REST CRUD app, and duplicating it makes it easy to see how using Jakarta Data is different from using Jakarta Persistence.

@scottmarlow FYI.

@emmartins

Copy link
Copy Markdown
Contributor

@bstansberry FYI no need to update any README.adoc, those are rebuilt if the related README-source.adoc is changed. You can keep such changes tho, no issue with that.

@bstansberry

Copy link
Copy Markdown
Contributor Author

True. I built that locally because I wanted to read the html page, and then forgot and added that to the commit.

Comment thread todo-backend/README-source.adoc Outdated

By default, it exposes a single datasource.
In the backend, the name of this datasource is `ToDos` and is specified in the `persistence.xml` to configure JPA:
In the backend, the name of this datasource is `ToDoRepository` and is specified in the `persistence.xml` to configure JPA:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops; it seems I made an edit to the wrong file. And even in the todo-jakarta-data QS this isn't correct.

@emmartins

Copy link
Copy Markdown
Contributor

Considering this was made on top of todo-backend, I suggest to redo this with current todo-backend, to inherit every change we did after this draft PR was submitted

@bstansberry

Copy link
Copy Markdown
Contributor Author

I have update this but the quickstart doesn't work. The server provisioning is not detecting / adding the jakarta-data layer. I'll start a zulip thread to investigate.

@bstansberry
bstansberry force-pushed the WFLY-21081 branch 2 times, most recently from 83888b5 to 05145f3 Compare November 23, 2026 22:19

@kstekovi kstekovi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the todo-jakarta-data quickstart - found three areas needing clarification: the update(Long id, ToDo update) logic in ToDoRepository.java:43 may not handle null IDs from PATCH requests correctly, README documentation references incorrect datasource/persistence-unit names in several places, and integration tests don't cover the PATCH/update operation. Otherwise the Jakarta Data implementation looks clean and effectively demonstrates the reduced boilerplate compared to the JPA version.

* @param update the updated ToDo to persist if one with the id exists. Cannot be {@code null
* @return an {@link Optional} containing the updated ToDo if a ToDo with {@code id} existed
*/
default Optional<ToDo> update(Long id, ToDo update) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a PATCH request, the update parameter typically has id=null (deserialized from HTTP body without id field). When you call update(update) with a null id, does Jakarta Data's @Update annotation handle this correctly?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The id should be coming from ToDoController which gets it from the request path, not the HTTP body.

I added two Objects.requireNonNull calls to this method. I went with that because that is what Hibernate Data Repositories does for the other methods in the impl of this interface that it generates. (So, passing null to update(ToDo) will result in "throw new NullPointerException("Null todo").)

Comment thread todo-jakarta-data/README-source.adoc Outdated

By default the provisioned `postgresql` add-on exposes a single datasource.

In the backend, the name of this datasource is `ToDoRepository` and is specified in the `persistence.xml` to configure JPA:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should "ToDoRepository" be changed to "ToDos"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Comment thread todo-jakarta-data/README-source.adoc Outdated
* `POSTGRESQL_SERVICE_HOST` - the host to connect to the database
* `POSTGRESQL_SERVICE_PORT` - The port to connect to the database
* `POSTGRESQL_USER` & `POSTGRESQL_PASSWORD` - the credentials to connect to the database
* `POSTGRESQL_DATASOURCE` - The name of the datasources (as mentioned above, it will be `ToDoRepository`)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should "ToDoRepository" be changed to "ToDos"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

*
* @author Emmanuel Hugonnet (c) 2022 Red Hat, Inc.
*/
public class RemoteToDoIT {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the test coverage include PATCH operation? This would verify the update(Long id, ToDo update) method works correctly (which is questioned in Point 2).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be good, yes.

The test was 100% copied from todo-backend, which doesn't test updates, and should as well. I won't promise to improve todo-backend as part of this but if I have time I will.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kstekovi I expanded the test coverage and added a commit doing that for todo-backend as well. I tweaked both quickstarts a bit as well to use the verb 'patch' instead of 'update' for some things, since the semantics of an HTTP PATCH are different from what Jakarta Data defines for @update and from what someone might intuitively expect for a database update.

Thanks for asking about this; the todo-jakarta-data QS wasn't properly doing a PATCH; it was assuming what was provided was a complete ToDo and that all its fields should be persisted. I fixed that.

Note that I still can't actually run the todo-jakarta-data integration test due to the problem I raised in my comment pinging Jean-Francois.

@bstansberry

Copy link
Copy Markdown
Contributor Author

@jfdenise This quickstart does not work correctly because wildfly-maven-plugin is not specifying the Jakarta Data layer.

--- wildfly:6.2.0.Final:package (default) @ todo-jakarta-data ---
[INFO] Glow is scanning... 
[INFO] Glow scanning DONE.
[INFO] context: bare-metal
[INFO] enabled profile: none
[INFO] galleon discovery
[INFO] - feature-packs
[INFO]    org.wildfly:wildfly-galleon-pack:43.0.0.Beta1-SNAPSHOT
[INFO]    org.wildfly:wildfly-datasources-galleon-pack:11.5.0.Final
[INFO] - layers
[INFO]    ee-core-profile-server
[INFO]    jaxrs
[INFO]    jpa
[INFO]    postgresql-datasource
[INFO] enabled add-ons
[INFO] - postgresql : Documentation in https://github.com/wildfly-extras/wildfly-datasources-galleon-pack
[INFO] identified fixes
[INFO] * unbound datasources error: java:jboss/datasources/ToDos is fixed
[INFO]   - add-on postgresql fixes the problem but you need to set the strongly suggested configuration.
[INFO] strongly suggested configuration at runtime
[INFO]  
[INFO] postgresql-datasource environment variables:
[INFO]  - POSTGRESQL_DATABASE=Defines the database name to be used in the datasource’s `connection-url` property.
[INFO]  - POSTGRESQL_JNDI=java:jboss/datasources/ToDos
[INFO]  - POSTGRESQL_PASSWORD=Defines the password for the datasource.
[INFO]  - POSTGRESQL_USER=Defines the username for the datasource.
[INFO] 
[INFO] Some suggestions have been found. You could enable suggestions with the <suggest>true</suggest> option.

The results ^^^ were from a run where I'd updated version.plugin.wildfly to 6.2.0.Final (vs 6.0.3 in this branch), in case that was relevant. I was also testing a 43.0.0.Beta1-SNAPSHOT instead of the 42.0.0.Final in this branch, in case my changes in wildfly/wildfly#20600 helped. I get the same results with the 6.0.3 plugin and 42.0.0.Final.

The Arquillian Glow plugin correctly suggests the jakarta-data layer in WF's testsuite/integration/smoke, both with my PR and in 42.x, so I think the layer itself is correct.

Any ideas?

@bstansberry
bstansberry force-pushed the WFLY-21081 branch 2 times, most recently from 4a9854e to baf6770 Compare November 24, 2026 22:07
@jfdenise

Copy link
Copy Markdown
Contributor

@bstansberry , the smoke tests work because some jakarta.data.X classes are used. In this quickstart we are only using jakarta.data.repository.X classes.
The rules in the layer expect only classes in the package jakarta.data: https://github.com/wildfly/wildfly/blob/main/ee-feature-pack/galleon-shared/src/main/resources/layers/standalone/jakarta-data/layer-spec.xml#L11-L12

We should replace the rule values with: jakarta.data.*

@bstansberry

Copy link
Copy Markdown
Contributor Author

@bstansberry , the smoke tests work because some jakarta.data.X classes are used. In this quickstart we are only using jakarta.data.repository.X classes. The rules in the layer expect only classes in the package jakarta.data: https://github.com/wildfly/wildfly/blob/main/ee-feature-pack/galleon-shared/src/main/resources/layers/standalone/jakarta-data/layer-spec.xml#L11-L12

We should replace the rule values with: jakarta.data.*

@jfdenise Thanks! wildfly/wildfly#20723

That fixes this QS. I'll put a workaround commit in that we can revert when 43 Beta is integrated with that fix.

@bstansberry
bstansberry marked this pull request as ready for review November 26, 2026 22:10
bstansberry and others added 3 commits November 26, 2026 16:11
…test

Rename and document the 'update' operation to properly describe its HTTP PATCH-like semantics

Also demonstrate proper cleanup of Jakarta REST client resources in the integration test
@bstansberry

Copy link
Copy Markdown
Contributor Author

@kstekovi @emmartins @mnovak @scottmarlow This works now.

I added a commit that works around the https://redhat.atlassian.net/browse/WFLY-22518 issue that I was discussing with @jfdenise . Once WF 43 Beta with that fixed is integrated that commit can be reverted.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants