Skip to content

Choose a tag to compare

@BalusC BalusC released this 26 Nov 18:10
675c1b3

Major release with an injectable EntityRepository for any entity type, auditing after commit, cacheable queries, and criteria and ordering which behave the same on every provider and database. Still Java 17 and Jakarta EE 10. Not binary compatible with 1.x: recompile your code against it. See "Breaking changes" and "Changes in behavior", and the upgrade notes. OptimusFaces 1.x does not run on OmniPersistence 2.0. Use OptimusFaces 2.0.

Breaking changes

  • Entities and services

    • Identifiable is removed. The ID of an entity is read from its @Id or @EmbeddedId via the JPA metamodel, so an entity only needs to drop implements Identifiable. BaseEntity declares getId() and setId(I) itself, so its subclasses are not affected. Code which uses Identifiable as a type no longer compiles: use Page.ID instead of Identifiable.ID, and EntityRepository#getId(E) to get the ID of any entity. #79
    • Provider#getIdentifier() is removed. Use getId() of EntityRepository or BaseEntityService instead. #79
    • The entity type of BaseEntityService, Provider, BaseEntityListener, AuditListener and the exceptions is no longer bound to BaseEntity, so that it works on any @Entity. Its erasure is now Object. A BaseEntityService subclass compiled against 1.x which overrides persist(), update() or delete() is silently bypassed until it is recompiled. #56
    • The find(), findFirst() and list() overloads of BaseEntityService delegate to the new Select variants. A subclass which overrides list(String, Object...) no longer sees the calls of find(String, Object...). #97
    • BaseEntityService has a new protected getId(E). A subclass with its own getId method of another signature may clash with it. #77
  • Paging and fetching

    • Page has moved from org.omnifaces.persistence.model.dto to org.omnifaces.persistence.query, next to the new Select. The model.dto package is removed. Update its import. #98
  • Auditing and configuration

    • getEntity() of AuditedChange and of BaseEntityException returns <E> E, because the entity type is no longer bound to BaseEntity. A chained call such as change.getEntity().getId() no longer compiles. Assign it to a variable of your entity type first, or use change.getEntityId(). #56 #66 #82

Changes in behavior

  • Entities and services

    • The entity name of the metamodel is used in JPQL and in AuditedChange#getEntityName(), instead of the simple class name. So an entity whose @Entity name differs from its class name works. Before, exists() and the JPQL of list(), find() and update() failed for it. #67
  • Paging and fetching

    • An entity without a fetched association, or without an optional association which is ordered or filtered on, is returned as well. These associations are joined with a LEFT JOIN. Before, an INNER JOIN left them out. #89
    • The database filters and orders the elements of a fetched collection by the criteria and the ordering of the page on their fields. So the collation of the database applies to them. A fetched collection which the ordering does not reference is ordered by its @OrderBy, else by the natural order of its elements. #104
    • ORDER BY is always applied. Before, it was skipped for a page of one row, such as Page.of(9, 10), which then came back unordered. Page.ONE returns the first record by the default ordering, id descending. #55
  • Criteria

    • A % or _ in the value of Like.contains(), startsWith() or endsWith(), and a [ on SQL Server, is matched as that character itself. Before, it acted as a wildcard in SQL but not in Like#applies(). These factories still add their own wildcards. Use Like.pattern() to match by wildcards of your own. #89
    • Like on a boolean field matches by the string value "true" or "false". Like.contains("1") no longer matches true. Use Bool.parse("1") for that. #81
    • Like#applies() and IgnoreCase#applies() ignore accents, so that they agree with an accent-insensitive collation of the column. The README lists such a collation per database. #106
    • Like and IgnoreCase on a java.time field match the date as yyyy-MM-dd and the time as HH:mm:ss, on every database and in applies(). #90
    • A null criteria on a @OneToMany, @ManyToMany or @ElementCollection matches the entities without elements, and Not.value(null) the entities with elements. Before, it matched nothing. #107
    • Not.value(v) also matches when the property is NULL. Not#applies() negates a wrapped Criteria, and matches a multi-value when none of its values matches. This is the same as in SQL. #89
    • Bool#applies() does not match null anymore, the same as in SQL. #89
    • A criteria value which cannot be parsed into the type of the field matches nothing. It is not skipped anymore. #89
    • A number matches an integral field by its numeric value, so 1.0 and "1.0" match 1, the same as Numeric#applies(). A value with a fraction, or beyond the range of the field, matches nothing. #110
    • Order#applies() and Between#applies() throw IllegalArgumentException when the model value cannot be compared with the criteria value. Before, they threw ClassCastException. Between#applies() compares numbers of different types by their numeric value, the same as Order#applies(). #110
    • A criteria or an ordering on a @Transient field resolves to the nearest @ManyToOne or @OneToOne which declares it, via a path of only @ManyToOne and @OneToOne. When several of the same depth declare it, or when only a path through a collection reaches it, it throws IllegalArgumentException. Before, which one won depended on hash order. Use the explicit path instead, such as lines.product.name. #110
    • An empty multi-valued criteria imposes no restriction on every kind of field. Before, it matched nothing on some kinds of fields and everything on others. #89
  • Auditing and configuration

    • AuditedChange is fired after the JTA transaction is committed, and not fired when it is rolled back. So the audit log reflects only changes which were actually committed. Because the transaction of the change has ended by then, an observer which persists an audit log must start a transaction of its own, for example via @Transactional(REQUIRES_NEW). #101

New features

  • Entities and services

    • EntityRepository<I, E>: inject it with concrete type arguments into any CDI or EJB managed bean, without a service class. The entity no longer needs to extend BaseEntity. Any @Entity with a single @Id or @EmbeddedId of any name works. #56
    • EntityRepository#getId(E) and #getEntityName(), also on BaseEntityService. #67 #77
    • Select: query options for find(), findFirst() and list(), such as Select.all().cacheable(true).build() for the 2nd level cache. #97
  • Paging and fetching

    • Page.with().range(offset, limit, lastOrderingValues, residualOffset, reversed): value based paging to a page whose previous page is not loaded. #55
    • Ordering on a field of a @OneToMany, @ManyToMany or @ElementCollection is correct across pages. The entities are ordered by the lowest element when ascending, else by the highest. #71 #95
    • A DTO page can be ordered by a collection field which the DTO does not map. On DB2 this throws IllegalArgumentException. Map an aggregate instead. #104
    • getPage() with fetches and a limit works without a transaction. #60
  • Criteria

    • Like.pattern() and JPA.escapeLike(): match by % and _ the same on every database and in applies(). #89
    • Optional criteria on an aggregate of a DTO page, such as count(phones). #96
  • Auditing and configuration

    • AuditedChanges: fired once per committed transaction, with all its AuditedChange instances in flush order. #103
    • AuditedChange#getEntityId(). #82

Bug fixes

  • All providers

    • Value based paging no longer drops rows when an ordering value is NULL. #89
    • getByIds() splits the IDs over several queries when they exceed the parameter limit of the database. #93
    • Criteria on an @ElementCollection behave the same on every provider, also in the count. #64 #65 #84
    • A criteria or ordering on an aggregate wrapped in a function, such as COALESCE(SUM(x), 0), goes in HAVING. #95
    • Between honors exclusive Range bounds in SQL. Numeric parses Double, Float, Short and Byte, and compares numbers by value across types and scales. #92 #94
    • Order and Between on an enum compare by declaration order, whatever the mapping. Like and IgnoreCase on an ordinal or converted enum match the same constants as in memory. #92 #95
    • A @ManyToMany behaves like a @OneToMany in criteria and ordering. #95
    • A field name ending in _in is no longer taken for an IN predicate. #99
    • An entity criteria directly on a @OneToMany or @ManyToMany, such as "phones", phone, works on every provider as a correlated EXISTS, and NOT EXISTS when negated. A multi-value matches the entities which contain all of them, the same as on an @ElementCollection. OpenJPA ignores it in the total count, see the known issues in the README. #110
    • getPage() excludes soft deleted rows also in the count query and the DB2 ID query. list(true) and getByIds(ids, true) include the soft deleted ones, like getById(id, true). #92 #94
    • @NonDeletable applies to a Hibernate proxy and a subclass as well. #99
    • AuditListener compares audited values by value and snapshots mutable values as a copy. The entity and audit listeners fire their events once CDI is available. #99
    • SwitchableXADataSource#getXAConnection(user, password) passes the credentials on. A data source config file with an unknown, read-only or unconvertible property throws IllegalArgumentException naming it. #92 #95
  • Hibernate

    • With Hibernate 7.4, getPage() with a collection fetch and a limit no longer fails with SQLGrammarException. #60
    • getById() and getSoftDeletedById() dereference a Hibernate proxy before they check the soft delete field. Before, a soft deleted entity which was already in the persistence context came back. #94
  • EclipseLink

    • getPage() of a page which is not cacheable no longer fails with EclipseLink-6030. #93
    • A criteria with many numeric or enum values no longer overflows the parser stack of H2, because it becomes one IN. #93
    • getByIds() and the postponed fetch of an entity with an @EmbeddedId work on SQL Server and DB2. #93
  • OpenJPA

    • A page which is not cacheable bypasses the 2nd level cache. Before, it was still served from the cache, because OpenJPA ignores the standard cache mode hints on a query. #95
    • An unranged getPage() ordered on a collection no longer fails with ClassCastException. #93
    • An array field such as byte[] is no longer taken for a collection, so fetchLazyBlobs(), fetchLazyMaps() and fetchLazyCollections() work. #93
    • An entity with an @EmbeddedId works in exists(), the count, ordering and EXISTS subqueries. #93
  • EclipseLink and OpenJPA

    • A criteria on a @OneToMany field no longer returns an entity once per matching element on EclipseLink and OpenJPA. So a page holds as many entities as its limit. #70
    • Value based paging on an aggregate of a DTO page no longer puts COUNT() in the WHERE clause on EclipseLink and OpenJPA. #89
    • JPA.concat() renders CONCAT() on SQL Server with EclipseLink and OpenJPA. #104
  • PostgreSQL

    • castAsString() of a java.time value works on PostgreSQL, DB2 and SQL Server, and of a number on PostgreSQL. Before, it gave wrong output or failed, such as for an OffsetTime on PostgreSQL. #90 #92
    • Like on a boolean field works on PostgreSQL. Before, it failed, because PostgreSQL has no LOWER() on a boolean. #81

Tested on

The integration tests now run on H2, PostgreSQL, MySQL, SQL Server and DB2, each on WildFly 42.0.0 with Hibernate 7.4.13, GlassFish 8.0.5 with EclipseLink 5.0.2 and TomEE 10.2.0 with OpenJPA 4.1.1. #63 #85 #86 #87 #88

Much of this release is hardening. AI assisted probes searched the code for untested edge cases. The gaps they found got tests, and the bugs those tests exposed were fixed or listed as known issues. A final check held every claim in the README and the javadoc against the code and the tests.

The README lists the known issues per provider and database.

🤖 Written with Claude Opus 5.5