Moved @PersistenceContext annotation to the setter method to make it overridable and thus re-configurable. Introduced protected getEntityManager() method to allow subclasses having access to the EntityManager.
Repository query methods can now be equipped with a @Lock annotation that carries the LockModeType to be used when executing the query. Beyond that, CRUD methods can be redeclared to carry lock metadata as well.
interface UserRepository extends Repository<User, Long> {
// CRUD method redeclaration
@Lock(LockModeType.READ)
List<User> findAll();
// Query method
@Lock(LockModeType.READ)
List<User> findByLastname(String lastname);
}
For pagination we already need to trigger a count query to find out the total number of pages available. Now if there are less elements available than the offset of the current page points to we don't need to trigger the actual content reading query at all. E.g. if there's only 20 elements in the database and we request page 3 by a page size of 10 we already know that there won't be any elements found.
Implemented that optimization for general CRUD pagination as well as pagination in query methods.
Query derivation mechanism now supports True and False as keywords in finder methods:
class User {
boolean active;
}
interface UserRepository<User, Long> {
List<User> findByActiveTrue() ;
}
Added ClasspathScanningPersistenceUnitPostProcessor that will scan the configured base package for classes annotated with @Entity or @MappedSuperclass and add them to the PersistenceUnit handled.
Beyond that it will scan for JPA XML mapping files if an optional mapping file name pattern is configured on the PUPP instance.
@Query now has a name attribute that allows defining the NamedQuery name to be used to override the convention based ${domainClass}.${finderMethodName}.
@Query can now be used to execute native queries by setting the nativeQuery flag of the annotation to true. Polished JavaDoc of the @Query annotation. Upgraded EclipseLink dependency to 2.3.1 as we stumble over a NullPointerException otherwise which is fixed in the current one.
Removed @Required annotation from the setter for EntityManager property. The annotation triggered a dependency check that was not aware of the EntityManager being injected by a PersistenceAnnotationBeanPostProcessor. As we already have a validation callback using @PostConstruct we can simply rely on the not-null check for the EntityManager being implemented there.
The actual fix for this ticket has been introduced during the refactoring for DATAJPA-86 (04349d25dc) thus it's already fixed in 1.1.0.M1. Added a test case to verify the behavior.
JpaQueryCreator hands Comparable into ParameterExpressionProvider to create ParameterExpression instances for Comparables. The ParameterExpressionProvider in turn now inspects the actual Parameter type and hand this one into the builder in case it's assignable (read: more concrete) to the given type requested.
Mention PersistenceExceptionTranslator being activated when using the JPA namespace. Documented custom namespace attributes special to the JPA namespace.
Added handling of count methods for queries using group by. In case the count query returns multiple results we use the number of results instead of failing. If the result contains one result we use this one.
Moved hint handling to AbstractJpaQuery.
We now don't catch an IllegalArgumentException being thrown in case a domain class is not found in the metamodel. If it occurs there's nothing we can do about it as we can't come up with an EntityInformation instance then and the persistence provider couldn't handle it anyway.
The query creation subsystem now supports using IgnoreCase when referencing String parameters, e.g.:
findByUsernameIgnoreCase(String username);
Both 'IgnoreCase' and 'IgnoringCase' are supported. If you'd like to entirely ignore cases for all String property references add 'AllIgnoreCase' or 'AllIgnoringCase' to the query method.
We now eagerly create CriteriaQuery and it's ParameterExpressions in QueryPreparer's constructor. Lazily doing so could let to exceptions accessing the ParameterExpressions in race conditions.
JpaQueryCreator is stateful as we create a list of ParameterExpressions and iterate over them. So we have to re-instantiate the JpaQueryCreator to not create an exception on the second attempt.