StringQuery now hints to the usage of @Param on query method parameters if named parameters are used and parameter names were not declared.
Original pull request: #77.
JpaMetamodelEntityInformation prefers the entity name from the JPA meta-model over the one derived from the simple class name. Documented limitation of an entity name customized through XML mapping metadata will not be considered in the SpEL support for manually defined query methods.
Original pull request: #76.
We now execute a query as a SingleEntityExecution if the return-type of the particular query-method is an basic char[],Character[], byte[], Byte[].
Previously we tried to do an CollectionExecution which didn't return all elements of the actual result (e.g. the byte[]).
Although EclipseLink and Hibernate support the use of array elements in projections OpenJPA seems not to. Filed https://issues.apache.org/jira/browse/OPENJPA-2484 to track the issue. Since OpenJPA prevents the bootstrap of the whole test suite I had to comment the query method + tests out. Tested Hibernate / EclipseLink by temporarily excluding all OpenJPA tests from the test-suite.
Original pull request: #71.
Removed the additional deleted flag in @Query as we currently already ship with a method to manually implement delete-queries (using @Modifying and a manually defined JPQL query).
Tiny optimization in DeleteExecution.
Original pull request: #66.
Added implementation of deleteBy / removeBy support for JPA backed repositories. We delete entities by looking them up with the appropriate query and delete them afterwards via entityManager.remove(...). This is rather inefficient but provides the benefit of being able to use the query derivation mechanism for entity deletion as well.
Original pull request: #66.
We now support load-graph / fetch-graph QueryHints on repository query methods, which are applied when a JPA 2.1 capable JPA implementation is used. We explicitly reject the usage of those hints in case the user is running a JPA 2.0 provider.
FetchGraphs / LoadGraphs can now be defined on the Entity via the @NamedEntityGraphs annotation.
@Entity
@QueryEntity
@NamedEntityGraphs(@NamedEntityGraph(name = "GroupInfo.members", attributeNodes = @NamedAttributeNode("members")))
public class GroupInfo {
@ManyToMany List<GroupMember> members = new ArrayList<GroupMember>(); //default fetch mode is "lazy".
}
The entity graph "GroupInfo.members" overwrites the fetch-mode of the members collection to be "eager".
The entity graph to be used can now configured on a repository query method.
@Repository
public interface GroupRepository extends CrudRepository<GroupInfo, String> {
@EntityGraph("GroupInfo.members")
GroupInfo getByGroupName(String name);
}
The new method JpaQueryMethod#getEntityGraph analyses an @EntityGraph annotation and constructs a new JpaEntityGraph value object that contains the information form the annotation. The new method AbstractJpaQuery#applyEntityGraphConfiguration tries to apply the given EntityGraph configuration if the used JPA persistence provider supports the JPA 2.1 spec.
Changed the class path order such that EclipseLink is now placed before the eclipse dependency. EclipseLink references the JPA 2.1 API and allows us to provide type-safe support for the new JPA 2.1 features.
Original pull request: #74.
Added test case to verify that sorting by nested embedded attributes with querydsl expressions works. Previously a ClassCastException was thrown due to changes in org.springframework.data.jpa.repository.support.Querydsl.
Original pull request: #70.
The configuration subsystem now sets up an AuditingHandler with a direct reference to a MappingContext. We now also wire an ObjectFactory into the AuditingEntityListener instead of the AuditingHandler directly.
This also lets us get rid off the need to mark AuditorAware instances as lazy initialized as the initialization chain is interrupted right at the AuditingEntityListener.
Related issues: DATACMNS-365.
Extended the mechanism previously existing to detect @Lock annotations on redeclared CRUD methods into one being able to transport arbitrary metadata into the execution of CRUD methods.
Renamed LockModeRepositoryPostProcessor to CrudMethodMetadataPostProcessor, refactored the internals and added some metadata caching to avoid repeated reflection lookups to evaluate annotations.
Replaced custom left join generation logic with default Querydsl mechanisms including support for ordering by arbitrarily nested property paths. Added test cases that demonstrate ordering by nested association paths (>= 2 levels). Added additional test cases for sort by nested property path expressions based on querydsl meta model and plain string based path expressions.
Original pull request: #65.
This works as expected with 3.6.10, 4.2.10, 4.3.4 but fails with 4.1.12.
Added test case to verify and track the issue with Hibernate 4.1.x. Renamed test-class from DataJpa269RepositoryWithCompositeKeyTests to RepositoryWithCompositeKeyTests.
Original pull request: #61.
Added support for Slice as return type for query methods. The execution will expand the requested page size by one to read one more element than actually requested. If that additional element is returned, it will considered to be an indicator for whether a next slice is available.
Related issues: DATACMNS-397.
Hibernate invalidly returns null for getModel() on its PluralAttribute implementation which causes the necessity for joins not having been detected previously.
We now fall back to joining in case we don't find a Model and deal with a PluralAttribute.
Instead of creating an individual instance of JpaMetamodelMappingContext per repository we now register a unique instance with access to the metamodel of the EntityManager the repositories use under "jpaMappingContext".
Weakened the contract in JpaPersistentEntityImpl to allow multiple @Id properties (in case @IdClass is used). The mapping context now also allows looking up of embeddable types as they're considered entities in the context of Spring Data mapping metadata.
When a parameter was listed with parentheses we didn't detect a custom binding and fell back to the standard binding. This effectively disabled the array-to-collection binding which is currently necessary for in bindings as some persistence providers do not bind arrays to in-clauses correctly.
Tweaked the regular expression to detect the bindings to accept the optional parentheses.
Query parameter binding replacements were undone if a simple binding was contained in the query. Fixed that and also make sure we don't create superfluous multiple bindings for the same variable and binding type.
We now always create a ParameterBinding for all parameters to simplify the client code so that it can safely always lookup bindings and apply them.
Changed the setup of the regular expression to work with the keywords provided by the binding types to ease future extensions.
Added integration test to quickly verify the EclipseLink bug we're running into now for further reference.
Original pull request: #56.
Enhanced binding of parameters in StringQueryParameterBinder to be able to deal with situations where a parameter value has to be converted to be correctly bound e.g. for parameter values in IN-expressions.
We now only convert array values to collections if the value is to be bound in the context of an IN-parameter. Previously we erroneously always converted an array value to a collection value which lead to problems if an array value was meant to be used "as-is" e.g. in cases where an user wants to query for a certain byte[].
Original pull request: #56.
QueryUtils now only creates a join for collection properties that are explicitly annotated with an @ManyTo… annotation. This allows collection like properties like byte[] be referred to as non-collection property and thus not trigger a join when a derived query is created.
The AuditingBeanFactoryPostProcessor and EntityManagerBeanDefinitionPostProcessor now correctly lookup BeanDefinitions within BeanFactory hierarchies. Also, the EMBDPP registers the EntityManager bean definition in the BeanFactory, the source BeanDefinition for the EntityManagerFactory is found.
Enabling repositories now registers a BeanFactoryPostProcessor that will register a SharedEntityManagerCreator BeanDefinition for all EntityManagerFactory definitions available in the ApplicationContext.
We register the bean name of the EMF as qualifier for the BeanDefinition for the EntityManager to allow an explicit reference in multi-EMF scenarios.
Renamed default persistence unit to spring-data-jpa.
Was able to upgrade to EclipseLink 2.5.1 and re-enable a previously ignored integration tests. However, some of the disabled test cases still fail despite the relevant bug being reported as fixed in 2.5.1.
Turned the workaround in QueryUtils into a TODO for removal as we don't want to strongly force EclipseLink users to upgrade to 2.5.x yet.
From the CDI extension we now use the callback newly introduced in Spring Data Commons to enable it to trigger eager initialization.
See also: DATACMNS-416.
Since the location of the Hibernate EntityManager implementation changed in Hibernate 4.3 to org.hibernate.jpa.HibernateEntityManager, we now support org.hibernate.jpa.HibernateEntityManager as well as org.hibernate.ejb.HibernateEntityManager as a Hibernate PersistenceProvider.
Original pull request: #55.
Latest Hibernate 4.3 releases have changes some behavior and internals slightly. Adapted the test cases accordingly and added another guard in JpaMetamodelEntityInformation to adhere to the new behavior.
Added build profile to be able to build against Hibernate 4.3.
Decided to go with a simpler way of building up attribute paths on JpaSort to avoid the need to work with JPA Path instances (and thus the EntityManager) entirely. Added shortcut constructors to JpaSort that take a vararg of Attribute or PluralAttribute respectively.
Interestingly, the test cases still have to be integration tests as the fields in the statically generated meta-model are null until the EntityManagerFactory bootstrap process enhances them to contain actual values. So no real unit tests unfortunately.
Consolidated tests cases for MailMessageRepository into one class, especially to avoid the configuration QueryDslRepositorySupportIntegrationTests to interfere with the newly added tests. Also rather use SampleConfig configuration class to allow the test framework's caching mechanism to kick in.
Original pull request: #54.
Introduced JpaSort for sorting by JPA meta-model attribute paths. Introduced JpaMetaModelPathBuilder that can be used to ease the construction of Jpa meta-model attribute paths by the provided static factory method. Added new testing scenario (MailMessage and MailSender) to avoid to mess up the existing sample classes. Enabled static JPA meta-model generation in pom.xml.
Enhanced Querydsl to generate appropriate left joins when sorting by nested (singular) association properties. Converted XML configuration for QueryDslRepositorySupportIntegrationTests into JavaConfig.
Original pull request: #54.
Previously sorting by property of an associated object generated an inner join instead of a left join with QueryDsl and Hibernate. That excluded records that had null values on their join columns. We now generate appropriate left joins if we detect associations in the sort property expression.
Ignored test cases for EclipseLink since eclipse link generates an inner-join instead of an outer-join to fetch associations in order by. Filed: https://bugs.eclipse.org/bugs/show_bug.cgi?id=422450
Original pull request: #53.
Polished the implementation of AuditingBeanFactoryPostProcessor to selectively add depends-on clauses to all bean definitions that will result in EntityManagerFactory instances eventually. Added unit tests to verify intended behavior for Java based configuration. Polished newly integrated test cases.
Removed obsolete code from AuditingEntityListener. Added configuration sample snippet. Polished reference documentation.
Original pull request: #50.
ExpressionBasedStringQuery now resolves and evaluates SpEL expressions of the actual query in the constructor and passes the resolved query to the StringQuery constructor. This enables the alias detection mechanism to work properly.
Original pull request: #51
Simplified implementation of ParameterBinder.convertToCollectionIfNecessary(…).
Added a simpler test case for plain query execution and ignored that for EclipseLink and OpenJpa as it fails with both the EclipseLink and OpenJpa versions we currently rely on. See the ignored test cases for links to bug reports.
Original pull request: #45.
In order to support query methods with array-typed parameters (e.g. parameters passed in as varargs) correctly we have to convert such an array into a collection. Previously we passed those parameters as is which led to Exceptions in EclipseLink and Hibernate, e.g. Hibernate: IllegalArgumentException: Encountered array-valued parameter binding, but was expecting [java.lang.Integer].
Refer to the JPA ticket instead of the DATACMNS one. Use Repository instead of JpaRepository in test cases. Some code formatting.
Original pull request: #46.
Support for considering nested repository interfaces can now be configured on the EnableJpaRepositories annotation via the considerNestedRepositories property. Previously nested repository definitions were ignored by the repositories infrastructure. This depends on DATACMNS-90.
Original pull request: #46.
Added a getOne(ID id) method to both JpaRepository as well as SimpleJpaRepository to be able to obtain references to entities (as implemented by EntityManager.getReference(…)).
So far, ClasspathScanningPersistenceUnitPostProcessor threw an IndexOutOfBoundsException on Windows as the OS-specific file separator doesn't match the forward slash used in the URI. This is fixed by modified scanForMappingFileLocations() to use '/' to build up the resource path.
Original pull request: #44.
Extracted the functionality specific to the handling of native queries out of SimpleJpaQuery and moved that to the new NativeJpaQuery type. Moved common functionality to AbstractStringBasedJpaQuery and used that as a new base class for SimpleJpaQuery and NativeJpaQuery. Introduced JpqQueryFactory to centralize construction of JpaQuery objects. Renamed getQuery() method in StringQuery to getQueryString().
Original pull request: #36.