Repository navigation
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
Identifiableis removed. The ID of an entity is read from its@Idor@EmbeddedIdvia the JPA metamodel, so an entity only needs to dropimplements Identifiable.BaseEntitydeclaresgetId()andsetId(I)itself, so its subclasses are not affected. Code which usesIdentifiableas a type no longer compiles: usePage.IDinstead ofIdentifiable.ID, andEntityRepository#getId(E)to get the ID of any entity. #79Provider#getIdentifier()is removed. UsegetId()ofEntityRepositoryorBaseEntityServiceinstead. #79- The entity type of
BaseEntityService,Provider,BaseEntityListener,AuditListenerand the exceptions is no longer bound toBaseEntity, so that it works on any@Entity. Its erasure is nowObject. ABaseEntityServicesubclass compiled against 1.x which overridespersist(),update()ordelete()is silently bypassed until it is recompiled. #56 - The
find(),findFirst()andlist()overloads ofBaseEntityServicedelegate to the newSelectvariants. A subclass which overrideslist(String, Object...)no longer sees the calls offind(String, Object...). #97 BaseEntityServicehas a newprotected getId(E). A subclass with its owngetIdmethod of another signature may clash with it. #77
-
Paging and fetching
Pagehas moved fromorg.omnifaces.persistence.model.dtotoorg.omnifaces.persistence.query, next to the newSelect. Themodel.dtopackage is removed. Update its import. #98
-
Auditing and configuration
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@Entityname differs from its class name works. Before,exists()and the JPQL oflist(),find()andupdate()failed for it. #67
- The entity name of the metamodel is used in JPQL and in
-
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, anINNER JOINleft 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 BYis always applied. Before, it was skipped for a page of one row, such asPage.of(9, 10), which then came back unordered.Page.ONEreturns the first record by the default ordering,iddescending. #55
- 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
-
Criteria
- A
%or_in the value ofLike.contains(),startsWith()orendsWith(), and a[on SQL Server, is matched as that character itself. Before, it acted as a wildcard in SQL but not inLike#applies(). These factories still add their own wildcards. UseLike.pattern()to match by wildcards of your own. #89 Likeon a boolean field matches by the string value"true"or"false".Like.contains("1")no longer matchestrue. UseBool.parse("1")for that. #81Like#applies()andIgnoreCase#applies()ignore accents, so that they agree with an accent-insensitive collation of the column. The README lists such a collation per database. #106LikeandIgnoreCaseon ajava.timefield match the date asyyyy-MM-ddand the time asHH:mm:ss, on every database and inapplies(). #90- A
nullcriteria on a@OneToMany,@ManyToManyor@ElementCollectionmatches the entities without elements, andNot.value(null)the entities with elements. Before, it matched nothing. #107 Not.value(v)also matches when the property isNULL.Not#applies()negates a wrappedCriteria, and matches a multi-value when none of its values matches. This is the same as in SQL. #89Bool#applies()does not matchnullanymore, 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.0and"1.0"match1, the same asNumeric#applies(). A value with a fraction, or beyond the range of the field, matches nothing. #110 Order#applies()andBetween#applies()throwIllegalArgumentExceptionwhen the model value cannot be compared with the criteria value. Before, they threwClassCastException.Between#applies()compares numbers of different types by their numeric value, the same asOrder#applies(). #110- A criteria or an ordering on a
@Transientfield resolves to the nearest@ManyToOneor@OneToOnewhich declares it, via a path of only@ManyToOneand@OneToOne. When several of the same depth declare it, or when only a path through a collection reaches it, it throwsIllegalArgumentException. Before, which one won depended on hash order. Use the explicit path instead, such aslines.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
- A
-
Auditing and configuration
AuditedChangeis 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 extendBaseEntity. Any@Entitywith a single@Idor@EmbeddedIdof any name works. #56EntityRepository#getId(E)and#getEntityName(), also onBaseEntityService. #67 #77Select: query options forfind(),findFirst()andlist(), such asSelect.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,@ManyToManyor@ElementCollectionis 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
-
Auditing and configuration
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
@ElementCollectionbehave 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 inHAVING. #95 Betweenhonors exclusiveRangebounds in SQL.NumericparsesDouble,Float,ShortandByte, and compares numbers by value across types and scales. #92 #94OrderandBetweenon an enum compare by declaration order, whatever the mapping.LikeandIgnoreCaseon an ordinal or converted enum match the same constants as in memory. #92 #95- A
@ManyToManybehaves like a@OneToManyin criteria and ordering. #95 - A field name ending in
_inis no longer taken for anINpredicate. #99 - An entity criteria directly on a
@OneToManyor@ManyToMany, such as"phones", phone, works on every provider as a correlatedEXISTS, andNOT EXISTSwhen 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)andgetByIds(ids, true)include the soft deleted ones, likegetById(id, true). #92 #94@NonDeletableapplies to a Hibernate proxy and a subclass as well. #99AuditListenercompares audited values by value and snapshots mutable values as a copy. The entity and audit listeners fire their events once CDI is available. #99SwitchableXADataSource#getXAConnection(user, password)passes the credentials on. A data source config file with an unknown, read-only or unconvertible property throwsIllegalArgumentExceptionnaming it. #92 #95
- Value based paging no longer drops rows when an ordering value is
-
Hibernate
- With Hibernate 7.4,
getPage()with a collection fetch and a limit no longer fails withSQLGrammarException. #60 getById()andgetSoftDeletedById()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
- With Hibernate 7.4,
-
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@EmbeddedIdwork 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 withClassCastException. #93 - An array field such as
byte[]is no longer taken for a collection, sofetchLazyBlobs(),fetchLazyMaps()andfetchLazyCollections()work. #93 - An entity with an
@EmbeddedIdworks inexists(), the count, ordering andEXISTSsubqueries. #93
-
EclipseLink and OpenJPA
- A criteria on a
@OneToManyfield 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 theWHEREclause on EclipseLink and OpenJPA. #89 JPA.concat()rendersCONCAT()on SQL Server with EclipseLink and OpenJPA. #104
- A criteria on a
-
PostgreSQL
castAsString()of ajava.timevalue works on PostgreSQL, DB2 and SQL Server, and of a number on PostgreSQL. Before, it gave wrong output or failed, such as for anOffsetTimeon PostgreSQL. #90 #92Likeon a boolean field works on PostgreSQL. Before, it failed, because PostgreSQL has noLOWER()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