back to all blogsSee all blog posts

Jakarta Data preview update in Open Liberty

image of author
Michal Broz on Apr 18, 2023
Post available in languages:

Open Liberty updates the Jakarta Data preview with an option to combine multiple ways to specify ordering and sorting.

The Open Liberty includes the following beta features (along with all GA features):

A Very Early Preview of Jakarta Data (Beta 2)

In Open Liberty, we introduced a very early preview of Jakarta Data, which aims to standardize the popular Data Repository pattern across relational and NoSQL databases.

This Jakarta Data beta update allows you to combine multiple ways of specifying ordering and sorting, defining a precedence. Sorting that is defined by the OrderBy annotation or query-by-method keyword is applied first, followed by Sort parameters on the method or Pageable.

Building on from the code snippet provided in the original preview, the following example uses both OrderBy and Sort:

public class Product { // entity
    public long id;
    public String name;
    public float price;

public interface Products {
    Product findById(long productId);

    List<Product> findByNameContains(String searchFor);

    Page<Product> findByNameIgnoreCaseContains(String searchFor, Pageable pageRequest);

    @Query("UPDATE Product o SET o.price = o.price - (?2 * o.price) WHERE = ?1")
    boolean discount(long productId, float discountRate);

    void save(Product p);

public class MyServlet extends HttpServlet {
    Products products;

    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        // Find all matching:
        List<Product> all = products.findByNameContains(searchFor);

        // Request only the first page, ordered by price, then name, then id:
        Pageable pageRequest = Pageable.size(20).sortBy(Sort.asc("name"), Sort.asc("id"));
        Page<Product> page1 = products.findByNameIgnoreCaseContains(searchFor, pageRequest);

Jakarta Data has not yet defined a standard configuration model. For now, the Open Liberty beta reuses the existing defaultDatabaseStore configuration for Jakarta Data, which defaults to the DefaultDataSource data source. As a result, the beta of Jakarta Data is currently limited to a single data source. This of course will change as the specification defines more of a configuration model. The data-1.0 Liberty beta feature makes the Jakarta Data API available, and you also need a feature for Jakarta Persistence or JDBC (or at some point in the future, Jakarta NoSQL).

Example server.xml configuration:

    <feature>persistence-3.1</feature> <!-- could use jdbc-4.3 instead -->
    <feature>servlet-6.0</feature> <!-- the example includes a servlet -->

  <dataSource id="DefaultDataSource">
    <jdbcDriver libraryRef="PostgreSQL"/>
    <properties.postgresql databaseName="testdb" serverName="localhost" portNumber="5432"/>
    <containerAuthData user="dbuser1" password="dbpwd1"/>

  <library id="PostgreSQL">
    <file name="${shared.resource.dir}/jdbc/postgresql.jar"/>

  <!-- optional because the following are all defaulted: -->
  <databaseStore id="defaultDatabaseStore" createTables="true" dropTables="false"
          tablePrefix="WLP" dataSourceRef="DefaultDataSource"/>

You can find the 1.0.0-b2 beta release of Jakarta Data on Maven, which corresponds to the Open Liberty beta.


For more information, refer to the the draft of the Jakarta Data specification and the corresponding Javadoc.

Your feedback is welcome on all of the Jakarta Data features and will be helpful as the specification develops further. Let us know what you think and/or be involved directly in the specification on github.

Try it now

To try out these features, update your build tools to pull the Open Liberty All Beta Features package instead of the main release. The beta works with Java SE 20, Java SE 17, Java SE 11, and Java SE 8.

If you’re using Maven, you can install the All Beta Features package using:


You must also add dependencies to your pom.xml file for the beta version of the APIs that are associated with the beta features that you want to try. For example, for Jakarta Data Beta 2, you would include:


Or for Gradle:

dependencies {
    libertyRuntime group: 'io.openliberty.beta', name: 'openliberty-runtime', version: '[,)'

Or if you’re using container images:


Or take a look at our Downloads page.

For more information on using a beta release, refer to the Installing Open Liberty beta releases documentation.

We welcome your feedback

Let us know what you think on our mailing list. If you hit a problem, post a question on StackOverflow. If you hit a bug, please raise an issue.