SimpleJpaRepository now deletes entities 1 by 1 for a call to deleteAll() to ensure the cascades get triggered. Introduced deleteAllInBatch() that contains the old behaviour.
Extracted the DateTime instance calculation to be used for auditing into a DateTimeProvider callback interface to open it up for customization. AuditingEntityListener can get an instance of it configured. Exposed the property via the auditing namespace. By default a CurrentDateTimeProvider its used that contains the behavior we had so far.
Introduced to support @IdClass to define entity ids. The JpeMetamodelEntityInformation builds instances of the annotated @IdClass in case any of the attributes of the entity declared in the @IdClass has a non-null value.
We will now prefer a declared NamedQuery for count queries instead of deriving it from the actual NamedQuery under the following conditions:
- by default a query named ${namedQueryName}.count exists
- the name of the NamedQuery to be used is defined in @Query(countQueryName = "…")
Note that a potential reconfiguration of the NamedQuery name will be taken into account for the according count query name to assure symmetry. Examples
Page<User> findByLastname(String lastname, Pageable pageable)
NamedQuery name: User.findByLastname
Count NamedQuery name: User.findByLastname.count
@Query(name = "Foo.bar")
Page<User> findByLastname(String lastname, Pageable pageable)
NamedQuery name: Foo.bar
Count NamedQuery name: Foo.bar.count
@Query(countName = "Foo.bar.count")
Page<User> findByLastname(String lastname, Pageable pageable)
NamedQuery name: User.findByLastname
Count NamedQuery name: Foo.bar.count
@Query(name = "Foo.bar", countName = "something")
Page<User> findByLastname(String lastname, Pageable pageable)
NamedQuery name: Foo.bar
Count NamedQuery name: something
Override isPersistenceUnitOverrideAllowed() newly introduced in Spring 3.1.1 to indicate we can deal with persistence units of the same name. For Spring 3.0.x versions the implementation was not broken.
We now call Metamodel.managedClass(…) instead of Metamodel.entityType(…) to be able to detect ids in @MappedSuperclass types as well. Unfortunately this currently still fails with Hibernate as theit Metamodel implementation only considers entities. See [0] for further details.
[0] https://hibernate.onjira.com/browse/HHH-6896
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.
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.
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.
Added Sonargraph architecture description. Removed cyclic package dependency. Introduced JpaEntityInformationSupport to contain common getEntityName() method and serving as factory for JpaEntityInformation instances.
Upgraded to Querydsl 2.2.0. Added configuration to generate query classes for AbstractPersistable and AbstractAuditable. Package those query classes into the source JAR and compile it into the binary as well. Upgraded Mysema APT plugin to 1.0.2.
We now support extracting query definitions into a properties file which can be configured on the JpaRepositoryFactoryBean. The namespace will look for classpath*:META-INF/jpa-named-queries.properties by default.
The JpaQueryCreator now creates a CriteriaQuery using ParameterExpressions that have to be bound later on. Refactored the RepositoryQuery implementation hierarchy and JpaQueryExecution as binding has to be done by the query classes now. This required the introduction of a special CriteraQueryParameterBinder as well. It uses the ParameterExpressions of the CriteriaQuery to bind the actual query values later on.
We have to convert arrays passed into query method into collections as none of the major persistence providers support binding arrays to IN parameters currently.
Separated touch(…) methods for updating and creation as some persistence providers might hand in entities with IDs already assigned into a @PrePersist method and thus the isNew() check will fail.
Removed check for that capability (QueryExtractor.canExtractQuery()) from JpaQueryMethod and defer it into NamedQuery as we can handle derived queries and queries annotated with @Query regardless of that capability.
Made exception message a bit more verbose to give hints what to do if the exception occurs.