Commit Graph

358 Commits

Author SHA1 Message Date
Oliver Gierke
1477c18994 DATAJPA-790 - Polishing.
JavaDoc, formattgin, license years, author headers.

Related tickets: DATAJPA-684
Original pull request: #182.
2016-11-03 16:43:18 +01:00
Jocelyn Ntakpe
3f5467dc85 DATAJPA-790 - QueryException when applying @EntityGraph on findAll(Predicate,Pageable).
We now create the count query that's required for pagination queries without applying the query hints.

Related tickets: DATAJPA-684
Original pull request: #182.
2016-11-03 11:25:46 +01:00
Oliver Gierke
fc073672af DATAJPA-984 - Improved translation of one-element tuples in projections.
If a query returns a one-element tuple and that single element returned is type-compatible to the type to be returned we return it as is. Previously, we insisted on creating a Map from the tuple (which usually works for projection interfaces).

This is needed to support custom simple types (i.e. types that the JPA provider can convert itself but which are not exposed through the metamodel - usually types managed through JPA AttributeConverters or provider specific conversion mechanisms).
2016-10-21 09:10:20 +02:00
Oliver Gierke
19eca5f9e0 DATAJPA-974 - Query for tuples now uses joins correctly.
When creating the selections for a derived query using a projection we now explicitly create joins for plural attributes. Looks like Hibernate fails to create a proper query if the path is referred to via root.get(…) and the select clause includes references to other non-plural attributes.
2016-09-28 15:06:27 +02:00
Christoph Strobl
e5b398410c DATAJPA-970 - Remove explicit group name from alias detection pattern.
We now use the group index instead of an explicit name. This fixes problems when using the pattern on Java 6.

Original pull request: #181.
2016-09-23 10:22:51 +02:00
Oliver Gierke
5c41f5ad1a DATAJPA-965 - Polishing.
Removed some unnecessary overrides in JpaOrder.
2016-09-20 10:28:20 +02:00
Christoph Strobl
b8e7fecccc DATAJPA-965 - Fix potential blind SQL injection in Sort when used in combination with @Query.
We now decline sort expressions that contain functions such as ORDER BY LENGTH(name) when used with repository having a String query defined via the @Query annotation.

Think of a query method as follows:

@Query("select p from Person p where LOWER(p.lastname) = LOWER(:lastname)")
List<Person> findByLastname(@Param("lastname") String lastname, Sort sort);

Calls to findByLastname("lannister", new Sort("LENGTH(firstname)")) from now on throw an Exception indicating function calls are not allowed within the _ORDER BY_ clause. However you still can use JpaSort.unsafe("LENGTH(firstname)") to restore the behavior.

Kudos to Niklas Särökaari, Joona Immonen, Arto Santala, Antti Virtanen, Michael Holopainen and Antti Ahola who brought this to our attention.
2016-09-20 10:28:05 +02:00
Oliver Gierke
287104c2e3 DATAJPA-960 - Fixed alias detection for queries not containing an alias.
We're now more lenient against manually defined queries that do not contain aliases when adding order by clauses to them. The alias detection now doesn't accidentally pick up "where" anymore in case no primary alias is declared and the code applying the order by clause only qualifies the expressions created if there actually is an alias in the first place.
2016-09-07 18:47:39 +02:00
Oliver Gierke
585ada91f3 DATAJPA-956 - Fixed accidental pick up of non-EntityManagerFactor JNDI objects.
We now exclude all candidates beans that could theoretically become an EntityManagerFactory unless we definitely know so.

Previously bean definitions for JndiObjectFactoryBean that didn't expose an expected type (e.g. ones defined via JavaConfig) were propagated to the creation of a DefaultJpaContext.
2016-09-04 13:01:40 +02:00
Oliver Gierke
d75019bae9 DATAJPA-951 - Prevent preemptive conversion to Optional in JpaQueryExecution.
JpaQueryExecution applies a ConversionService to convert between low-level types such as integers, longs and byte arrays. That ConversionService also preemptively converts objects into JDK 8's Optional in case the invoked method's return type is Optional.

We now explicitly remove the converter taking care of the latter to avoid Optionals to be created before the actual result conversion is applied, as it needs to see the raw value to create DTOs or interface based projections correctly.
2016-08-17 16:31:30 +02:00
Oliver Gierke
937c650276 DATAJPA-938 - Enable DOTALL mode for regular expression detecting constructor expressions in manually declared queries.
The usage of the DOTALL mode makes sure that line breaks in query definitions don't cause any trouble when trying to detect constructor expressions.
2016-08-11 23:34:16 +02:00
Mark Paluch
9381d6a5a3 DATAJPA-912 - Fix broken test in RepositoryWithCompositeKeyTests.
Use a page size of 1 to enforce a count query creation. The expected exception is only visible with Hibernate 4.1.x when a count query is issued.

Related pull request: #174.
2016-08-04 20:57:47 -07:00
Oliver Gierke
21991ce5c6 DATAJPA-938 - Fixed constructor expression detection in QueryUtils.
Slightly loosened our regular expression to detect constructor expressions as previously it didn't match select expressions that contained a distinct clause.
2016-08-03 18:15:00 -07:00
Mark Paluch
1ea8096827 DATAJPA-937 - Fix format string in QueryByExamplePredicateBuilder.getPredicates. 2016-07-27 12:01:03 +02:00
Oliver Gierke
5ee723cbe0 DATAJPA-413 - Polishing.
Removed some unnecessary accessor methods.

Original pull request: #133.
2016-07-20 12:15:07 +02:00
Mark Paluch
529eff5a8f DATAJPA-413 - Guard identifier derivation against null values and add tests.
Added guard against null values in identifiers. Null values can occur because id generation was not completed yet. Add tests for identifier derivation using @IdClass for Hibernate, OpenJPA and EclipseLink.

Original pull request: #133.
2016-07-20 12:15:07 +02:00
Mark Paluch
edf63705c9 DATAJPA-912 - Optimize paged query execution.
We execute paged queries now in an optimized way. The data is obtained for each paged execution but the count query is deferred. We determine the total from the pageable and the results in which we don't hit the page size bounds (i.e. results are less than a full page without offset or results are greater 0 and less than a full page with offset). In all other cases we issue an additional count query.
2016-07-20 11:39:53 +02:00
Oliver Gierke
0fae610163 DATAJPA-929 - Further guards against null values returned from ManagedType.
Extracted the functionality to check for JPA managed types into a dedicated wrapper for the JPA Metamodel. This allows all clients to benefit from the null guards we have to put in place due to [0]. Adapted the fix introduced for DATAJPA-904 to make use of the newly created infrastructure, too.

[0] https://hibernate.atlassian.net/browse/HHH-10968
2016-07-19 10:53:02 +02:00
Oliver Gierke
8e616afdc4 DATAJPA-923 - Polishing. 2016-07-14 09:16:36 +02:00
Oliver Gierke
e4b9ba8e0e DATAJPA-923 - QueryByExamplePredicateBuilder now considers match mode.
We now inspect QueryByExamplePredicateBuilder.isAndMatching() to decide whether to concatenate the predicates built using and or or.

Related tickets: DATACMNS-879.
2016-07-14 09:16:17 +02:00
Oliver Gierke
0768bc4696 DATAJPA-904 - Guard against null values from JPA's ManagedType.getJavaType().
Some persistence providers (Hibernate *cough*) return null for a ManagedType's JavaType, which we perviously didn't expect in the implementation of JpaPersistentPropertyImpl.isEntity().

We now eagerly extract all managed types from the Metamodel and gracefully skip nulls so that we don't have to look up the types repeatedly.
2016-06-08 10:17:51 +02:00
Oliver Gierke
5c24fae1e5 DATAJPA-885 - Make sure manually defined queries returning domain type don't use tuples.
We now check manually defined queries for whether the projection is equal to the used alias and don't use a Tuple query in this case. This allows the manually defined queries to still define the projections manually but also the returned objects be wrapped with projection interfaces easily.
2016-06-07 18:22:44 +02:00
Oliver Gierke
fdede85931 DATAJPA-911 - Assert compatibility with Hibernate 5.2.
We now use a completely reflective lookup of the Hibernate query string as well as for the Hibernate specific PersistenceProvider lookup in tests.

Added build profile for Hibernate 5.2 but it's currently not working due to Hibernate complaining about an invalid identifier mapping on CustomAbstractPersistable which is overriding the parent types  property on accessor working fine on 5.1.

The build profile for 5.1 is still broken due to the fixed but yet unreleased HHH-10514 [0] and the not yet fixed HHH-10515 [1] (apparently fixed but still open and unreleased) which has been broken since 5.0.8.

[0] https://hibernate.atlassian.net/browse/HHH-10514
[1] https://hibernate.atlassian.net/browse/HHH-10515
2016-06-04 14:19:09 +02:00
Oliver Gierke
bf304095c3 DATAJPA-905 - Count queries for Specifications don't use orders anymore.
Count queries that are executed in the context of paginated queries using Specifications now get their order specifications removed as they get rejected by some databases.
2016-05-27 16:56:58 +02:00
Oliver Gierke
4637656268 DATAJPA-885 - Polishing.
Some cleanups in some test cases.
2016-04-09 15:41:20 +02:00
Oliver Gierke
d64494ade6 DATAJPA-885 - Tuple queries are now only issued for non-JPA managed types.
We now explicitly check the return types for queries using manually defined queries to find out whether it's a JPA managed type in the first place. Only if that's not the case we resort to a Tuple query and assume DTO mapping happening downstream.

This is necessary as a singular projection expression in the query might simply return an element of the aggregate and thus doesn't need any DTO creation. In case an unmanaged type is returned from the query method we assume DTO creation.
2016-04-09 15:41:03 +02:00
Oliver Gierke
ed7df2eceb DATAJPA-218 - Polishing.
Adapted to API changes in Spring Data Commons.

Related tickets: DATACMNS-810.
Original pull request: #164.
2016-03-17 16:35:54 +01:00
Mark Paluch
75f2719c61 DATAJPA-218 - Further work on Query by Example.
Add reference documentation. Adapted to API changes in Spring Data Commons.

Related tickets: DATACMNS-810.
Original pull request: #164.
2016-03-17 16:35:54 +01:00
Christoph Strobl
88abb0dbc3 DATAJPA-218 - Add Predicate based QBE implementation.
We convert a given Example to a set of and combined Predicates using CriteriaBuilder. Cycles within associations are not allowed and result in an InvalidDataAccessApiUsageException. At this time only SingularAttributes are taken into concern. Switched to types used in DATACMNS-810.

Related tickets: DATACMNS-810.
Original pull request: #164.
2016-03-17 16:35:54 +01:00
Thomas Darimont
6ec173bc9a DATAJPA-218 - Support extracting parameters from a bean parameter.
Added prototypic support for query by example queries to
SimpleJpaRepositories. Clients can use an Example object to
wrap an existing prototype entity instance that will be used to
derive a query from.

Related tickets: DATACMNS-810.
Original pull request: #164.
2016-03-17 16:35:53 +01:00
Christoph Strobl
a1509f9517 DATAJPA-871 - Allow usage of composed annotations using @AliasFor.
We allow and support composing annotations for: @Entity, @EntityGraph, @Lock, @Modifying, @Query, @QueryHints as well as @Procedure.

Original pull request: #166.
2016-03-16 19:10:58 +01:00
Oliver Gierke
154e3370cf DATAJPA-813 - Made JNDI EntityManagerFactory detection more lenient.
We now don't assume an expectedType property configured for every declaration of <jee:jndi-lookup /> but rather skip elements that don't have the attribute configured.
2016-03-07 11:40:51 +01:00
Oliver Gierke
a91a27ad00 DATAJPA-813 - Improved EntityManagerFactory detection for JndiObjectFactoryBeans.
The lookup of EntityManagerFactory bean definition now also detects JndiObjectFactoryBean instances that have the expected type configured to EntityManagerFactory.

Related ticket: DATACMNS-821.
2016-02-26 20:05:26 +01:00
Oliver Gierke
86d50bee2e DATAJPA-864 - Projection execution now considers constructor expressions in manually defined queries.
Previously we triggered a tuple query execution even if a query was manually defined and contained a constructor expression (e.g. new Dto(a.foo, a.bar)). We now explicitly detect that case and simply execute the query as is.
2016-02-15 13:15:43 +01:00
Oliver Gierke
75f294266f DATAJPA-858 - Polishing.
Removed obsolete method from JpaQueryCreator. Tweaked ticket references in sample repository.
2016-02-10 18:20:01 +01:00
Oliver Gierke
5455b8c8dc DATAJPA-858 - Fixed collection contains handling for nested path traversals.
Previously the first property was checked for being a collection to trigger collection contains handling. This is wrong for nested property traversals as they might end up in a String for which a like binding has to be applied then.

We're now inspecting the leaf property for being a collection to trigger that special binding.
2016-02-10 18:19:32 +01:00
Oliver Gierke
62595a5bda DATAJPA-813 - Advanced integration test for DefaultJpaContext.
Added an integration test that shows how to refer to JpaContext from an ApplicationComponent.
2016-01-19 12:59:58 +01:00
Oliver Gierke
418fbec2f7 DATAJPA-848 - Fixed AbstractPersistable's equals(…) for proxies.
AbstractPersistable.equals(…) now consides the target object's user class before comparing types.
2016-01-15 14:03:23 +01:00
Oliver Gierke
e668d800d1 DATAJPA-845 - Avoid unnecessary lookups of PersistenceProvider.
To prevent multiple attempts of class loading down stream for multiple lookup calls to fromEntityManager(…) or fromMetamodel(…). We now avoid the repeated lookups of a PersistenceProvider instance by reusing a canonical one created in CreateQueryLookupStrategy.

Instead of looking up the PersistenceProvider for every entity again, we now look it up once in the JpaMappingContext for reuse on all JpaPersistentEntity instances.

Original pull request: #161.
2016-01-11 15:33:42 +01:00
Oliver Gierke
aa895726d1 DATAJPA-839 - Fixed thread-bound lookups of CrudMethodMetadata.
CrudMethodMetadata exposed by the CrudMethodMetadataPostProcessor previously used an AbstractLazyCreationTargetSource to lookup the thread-bound instance. That instance however is cached and never released so that all subsequent calls to it returned the same (and in most cases wrong) instance.

We're now implementing TargetSource directly to make sure we obtain a fresh instance on every access of the CrudMethodMetadata proxy.
2015-12-17 17:28:09 +01:00
Oliver Gierke
d88f823c75 DATAJPA-804 - Support for projections on query methods.
Based on the work for DATACMNS-89 we now use the metadata exposed by ResourceProcessor to optimize queries that are to be projected on the query execution level.

If a projection interface is used that's not using any dynamic expression, we now explicitly query for a JPA Tuple consisting of all properties required for the projection interface. The same applies to DTOs that use an @PersistenceConstructor.

Related tickets: DATACMNS-89.
2015-12-14 19:44:29 +01:00
Oliver Gierke
f205dc16b2 DATAJPA-829 - Support for Contains keyword on collection expressions.
The if a collection expression is concluded with a Contains keyword, we now translate that into a "member of"-expression on the criteria query. This allows to check whether a collection property contains a singular value.

List<User> findByRolesContaining(Role role);

This will return all users that have the given role.
2015-12-02 08:09:18 +01:00
Oliver Gierke
e0a9f287ee DATAJPA-830 - NotContaining now gets applied correctly.
We now handle the NotContaining keyword correctly for String property expressions.
2015-12-02 07:40:54 +01:00
Oliver Gierke
51ff07c04c DATAJPA-765 - Upgraded to Querydsl 4. 2015-11-17 13:42:42 +01:00
Oliver Gierke
3f7fad1a6a DATAJPA-820 - Try to discover more version properties on superclasses.
Tweaked the lookup of a version property on a mapped superclass. Hibernate doesn't expose itself as being very supportive in that: on versions below 4.3 the method primarily intended to look it up (IdentifiableType.getVersion(…)) expects you to hand in exactly the type of the property you're trying to find in the first place. Awesome, not.

If this fails, we now explicitly traverse the singular attributes and recursively traverse super types. Unfortunately, on the Hibernate version broken as defined above, the check for attribute.isVersion() fails even for the version property as the implementation holds all singular attributes with one for the version property which is not marked as such.

tl;dr; - everyone trying to use @Version on a mapped superclass and a primitive identifier in an entity on Hibernate 4.3 will still have to implement Persistable to make sure EntityManager.persist(…) is used for new entities.
2015-11-06 11:38:53 +01:00
Oliver Gierke
b3324a0e7d DATAJPA-871 - CrudMethodMetadataPostProcessor now uses the bean ClassLoader.
The thread-local proxy for the CrudMethodMetadata is now created using the bean ClassLoader, which the repository factory gets set from the container.

Renamed the property for the post processor and its lookup method.
2015-11-05 19:01:19 +01:00
Oliver Gierke
a3e73a4c40 DATAJPA-815 - Fixed application of sorting in combination with join aliases.
The application of sort expressions is guarded by the detection of join aliases to potentially prefix the sort expression with the default alias. In case a raw property reference to sort by started with a join alias the property name wasn't prefixed. We now explicitly check for a start with the alias followed by a dot.
2015-10-21 11:24:21 +02:00
Oliver Gierke
7fb58c3c47 DATAJPA-809 - ParameterBinder now uses ParameterAccessor.
We now use a ParameterAccessor to obtain query method parameters in ParameterBinder to benefit from value post-processing (e.g. unwrapping of Optional etc.).

Related tickets: DATACMNS-768.
2015-10-07 19:39:37 +02:00
Oliver Gierke
7fa997085d DATAJPA-585 - Fixed potential NullPointerException in QueryDslJpaRepository.
findAll(Predicate, Pageable) now treats null Pageable instances correctly.
2015-10-06 07:34:12 +02:00
Oliver Gierke
945acce07d DATAJPA-808 - Introduced AttributeConverters for ZoneId for JSR-310 and ThreeTenBP. 2015-10-05 18:39:34 +02:00