Commit Graph

216 Commits

Author SHA1 Message Date
Thomas Darimont
09d32cb3f5 DATAJPA-527 - Improved handling of CrudRepository.exists(ID) entities with complex composite id.
We now delegate the exists(…) check to findOne(…) in SimpleJpaRepository for entities that have a complex composite id via @IdClass. Previously we tried to generate a string based count query in that case, which didn't work since the parameter types for the IdClass attributes didn't match the values returned by entityInformation.getCompositeIdAttributeValue(…).

Polished JavaDoc in JpaEntityInformation.

Original pull request: #95.
2014-06-17 13:32:15 +02:00
Thomas Darimont
0480843322 DATAJPA-545 - Fixed regression in discovery of StringQuery parameters.
Special characters like french accents (e.g., abonnés) were not allowed anymore (was in SD JPA 1.2) in named parameter bindings. Adjusted regex in StringQuery to cover a broader list of characters.

Original pull request: #93.
2014-05-22 11:56:47 +02:00
Oliver Gierke
13346c0115 DATACMNS-494 - Fix test setup in JpaRepositoriesRegistrarUnitTests.
We now explicitly set an Environment in JpaRepositoriesRegistrarUnitTests to make sure the registrar can work correctly.
2014-05-20 16:48:10 +02:00
Thomas Darimont
122d9c5ea2 DATAJPA-456 - Add support for specifying only the projection part of a custom count query.
We now support to specify just the projection part for the count query generation via the "countProjection" property of the @Query annotation.
This avoids having to repetitively specify parts of the original query.

Original pull request: #84.
2014-05-19 19:37:12 +02:00
Thomas Darimont
076b017d18 DATAJPA-525 - Guard against null types returned from JPA meta-model.
Some JpaProviders (read: Hibernate in combination with Hibernate Envers) sometimes return null values from ManagedType.getJavaType() for embedded types values.

We now explicitly check for null values before adding the type to the initial entity set processed by the mapping context.

Related pull request: #89.
2014-05-19 12:55:20 +02:00
Thomas Darimont
4d63856dde DATAJPA-510 - Fix regression when sorting by property of associated object.
The main problem was a bug in querydsl 3.3.2 that has been resolved resolved in querydsl 3.3.3 to which we just updated in in spring-data-build/#70.

Cleaner usage of querydsl API and less brittle casting. Added test case for sorting by nested association property that is wrapped in a function, e.g. lower(…).

Original pull request: #87.
2014-05-19 12:11:31 +02:00
Thomas Darimont
2c2355bc93 DATAJPA-499 - Querydsl now uses the null-handling configured on the Sort.Order.
We now propagate the null-handling hint defined in Order to an appropriate Querydsl null handling hint.

Original pull request: #82.
2014-04-29 09:07:55 +02:00
Thomas Darimont
09535813c2 DATAJPA-455 - Add support for stored procedure backed repository methods.
Added support for JPA 2.1 stored procedures mapping for repository methods. Introduced @Procedure annotation for declaring stored procedure metadata. Repository methods backed by stored procedures are represented as a StoredProcedureJpaQuery that is constructed by JpaQueryFactory#fromProcedureAnnotation.

Enhanced JpaQueryLookupStrategy to support @Procedure. Introduced StoredProcedureAttribute to capture the derived configuration for a stored procedure query.

The stored procedure needed for the tests is created via the schema-stored-procedures.sql script that is picked up by the customized DataSource definition in infrastructure.xml.

Added new test class UserRepositoryStoredProcedureTests to be able to exclude those tests for OpenJPA. OpenJPA tests don't work with hsqldb 2.x and use hsqldb 1.x instead which doesn't support stored procedures.

Original pull request: #80.
2014-04-28 12:43:46 +02:00
Oliver Wehrens
7c6f4528ef DATAJPA-513 - Improve error message on missing @Param on query method parameter.
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.
2014-04-14 10:39:13 +02:00
Thomas Darimont
ff0170967d DATAJPA-509 - JpaMetamodelEntityInformation now considers entity name from JPA meta-model.
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.
2014-04-14 09:43:02 +02:00
Thomas Darimont
44d7e2ef24 DATAJPA-505 - Projections for basic primitive arrays should use SingleEntityExecution.
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.
2014-03-31 15:03:07 +02:00
Oliver Gierke
3ff4f94c68 DATAJPA-460 - Reduce implementation to core requested feature.
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.
2014-03-31 14:38:14 +02:00
Thomas Darimont
99ae3c4567 DATAJPA-460 - Support query creation for deleteBy / removeBy prefix.
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.
2014-03-31 14:38:08 +02:00
Thomas Darimont
dd64fe21ea DATAJPA-466 - Add support for lazy loading configuration via JPA 2.1 fetch-/loadgraph.
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.
2014-03-30 16:42:36 +02:00
Thomas Darimont
8cc070c02d DATAJPA-500 - Verify that sorting of Embeddables with Querydsl works.
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.
2014-03-19 13:43:54 +01:00
Oliver Gierke
467903b96c DATAJPA-501 - Adapted auditing configuration to latest changes in Spring Data Commons.
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.
2014-03-18 20:06:47 +01:00
Thomas Darimont
e2e692ce83 DATAJPA-497 - Fixed handling of OrderSpecifier for Querydsl based repositories.
We now only generate an additional left-join for the order expression of the targetPath is an EntityPath.

Original pull request: #69.
2014-03-17 09:43:33 +01:00
Thomas Darimont
07976eac9c DATAJPA-496 - Fixed join creation for element collection attributes.
QueryUtils.toExpressionRecursively(…) now also creates joins for attributes mapped to an @ElementCollection.

Original pull request: #68.
2014-03-13 12:42:32 +01:00
Oliver Gierke
5438c44c8f DATAJPA-173 - Extended support for metadata detection on CRUD methods.
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.
2014-03-12 15:30:46 +01:00
Thomas Darimont
79b5330928 DATAJPA-491 - Support order by arbitrarily nested association paths with Querydsl.
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.
2014-03-12 11:12:52 +01:00
Oliver Gierke
d42a929d03 DATAJPA-493 - Upgraded to OpenJPA 2.3.0.
Upgraded to OpenJPA 2.3.0 and enabled test cases previously ignored because of bugs in previous versions.
2014-03-07 19:16:47 +01:00
Thomas Darimont
f5718e608c DATAJPA-464 - Add support for returning subtypes of Repository Entity in JpaRepository.saveAndFlush.
Adopted generic method declaration from save method to saveAndFlush.

Original pull request: #58.
2014-03-06 17:33:32 +01:00
Thomas Darimont
5f89cfd430 DATAJPA-472 - Verify that pagination works with entities with @IdClass.
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.
2014-03-06 17:25:12 +01:00
Oliver Gierke
c8ca0f80c4 DATAJPA-486 - Added support for sliced query execution.
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.
2014-03-06 10:30:57 +01:00
Oliver Gierke
8a1b4365a2 DATAJPA-476 - Mitigate spec violations in Hibernate for query creation.
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.
2014-03-04 11:20:48 +01:00
Oliver Gierke
bc9ee616ef DATAJPA-484 - Improved registration of JpaMetamodelMappingContext.
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.
2014-03-03 17:39:08 +01:00
Oliver Gierke
26c64eca0f DATAJPA-483 - Fixed parameter binding detection with parentheses.
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.
2014-02-27 10:11:33 +01:00
Oliver Gierke
10dd37a619 DATAJPA-473 - Fixed bug in binding detection in String queries.
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.
2014-02-23 14:11:06 +01:00
Oliver Gierke
992ccb5956 DATAJPA-471 - Ensure test succeed on Spring 4.
Annotated MappedTypeRepository test repository interface with @NoRepositoryBean to prevent it to fail the build on Spring 4.
2014-02-20 20:27:46 +01:00
Oliver Gierke
c0c1209130 DATAJPA-461 - Improve binding detection.
Improved the regular expression to detect binding detection to safely find as-is bindings.
2014-02-11 18:14:31 +01:00
Oliver Gierke
1d4b57f684 DATAJPA-461 - Polishing of binding implementation for StringQueries.
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.
2014-02-11 15:32:39 +01:00
Thomas Darimont
f8b0917c90 DATAJPA-461 - Fixed regression in parameter binding of arrays.
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.
2014-02-11 15:32:22 +01:00
Oliver Gierke
75d6f26572 DATAJPA-454 - Fixed join creation in QueryUtils.
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.
2014-02-06 19:19:27 +01:00
Oliver Gierke
7b9b303f05 DATAJPA-453, DATAJPA-435 - Fixed BeanFactoryPostProcessor handling of BeanFactory hierarchies.
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.
2014-01-27 12:41:57 +01:00
Oliver Gierke
7b5425322b DATAJPA-445 - Enable constructor injection for EntityManagers.
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.
2014-01-25 23:55:37 +01:00
Oliver Gierke
b1585377c2 DATACMNS-420 - Adapted test cases due to latest changes in Spring Data Commons. 2014-01-18 12:36:16 +01:00
Oliver Gierke
9640ea81ad DATAJPA-417 - Upgraded to EclipseLink 2.5.1.
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.
2014-01-17 17:12:20 +01:00
Oliver Gierke
f2bc6fc466 DATAJPA-442 - Enable CDI repositories to be instantiated eagerly.
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.
2014-01-13 12:04:14 +01:00
Thomas Darimont
5e8928f54f DATAJPA-444 - Improve detection of PersistenceProvider implementations.
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.
2014-01-08 16:36:08 +01:00
Komi Serge Innocent
a0a98dfc57 DATAJPA-420 - Fixed count projection for manual queries with projections.
Original pull request: #52.
2013-12-10 23:13:56 +01:00
Oliver Gierke
ae10332b18 DATAJPA-430 - Tweaks to be compatible with Hibernate 4.3.
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.
2013-12-09 14:44:13 +01:00
Oliver Gierke
1d6806b979 DATAJPA-12 - Design changes in JpaSort.
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.
2013-12-07 13:10:29 +01:00
Thomas Darimont
692b2382bf DATAJPA-12 - Added Sort implementations for JPA meta-model API and Querydsl.
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.
2013-12-07 13:09:31 +01:00
Thomas Darimont
e51add8c76 DATAJPA-427 - Generate left joins for referenced associations in sort expressions.
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.
2013-12-04 13:59:07 +01:00
Oliver Gierke
240ace24f3 DATAJPA-265 - Further polishing.
Original pull request: #50.
2013-11-12 12:04:20 +01:00
Oliver Gierke
80e1777a5b DATAJPA-265 - Improve implementation of AuditingBeanFactoryPostProcessor.
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.
2013-11-11 20:43:07 +01:00
Thomas Darimont
44806cb7f1 DATAJPA-265 - Support for auditing configuration via JavaConfig.
Introduces the necessary infrastructure to configure auditing with JPA via JavaConfig using @EnableJpaAuditing.

Original pull request: #50.
2013-11-11 20:20:05 +01:00
Thomas Darimont
23e27f3332 DATAJPA-424 - Fixed alias detection in manually defined queries using SpEL.
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
2013-11-07 13:50:46 +01:00
Oliver Gierke
9a279f83cf DATAJPA-419 - Adapt to new non-lazy-instantiation model of repositories.
Mostly mayor cleanups the way test cases bootstrap the repositories as they're now instantiated eagerly.
2013-11-05 16:41:48 +01:00
Oliver Gierke
e3b0148383 DATAJPA-405 - Guard against null predicates on query creation.
We now only call CriteriaQuery.where(…) if the predicate we handle is a non-null value. Adapted Jpa(Count)QueryCreator accordingly.
2013-10-27 17:41:50 +01:00