Commit Graph

588 Commits

Author SHA1 Message Date
Stanislav Bashkyrtsev
2fbdd53493 DATAJPA-993 - Improved example of infrastructure setup in reference documentation.
Previously EntityManagerFactory was created manually which resulted in LocalContainerEntityManagerFactoryBean not being exposed to
ApplicationContext. The latter is an important bean since it enables
exception translation.

Original pull request: #180.
2016-11-03 16:43:20 +01:00
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
Michał Niczyporuk
b2426d89ed DATAJPA-992 - Fixed package name in JavaDoc for AuditingEntityListener.
Original pull request: #183.
2016-11-03 10:47:12 +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
8756765866 DATAJPA-966 - Updated changelog. 2016-09-29 14:41:59 +02:00
Oliver Gierke
1a4ebb5eeb DATAJPA-975 - Updated changelog. 2016-09-29 11:42:02 +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
79bc398811 DATAJPA-964 - Updated changelog. 2016-09-21 08:03:35 +02:00
Oliver Gierke
b07bdc089d DATAJPA-916 - Updated changelog. 2016-09-21 08:03:34 +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
Oleksandr Mandryk
9d0120d6c6 DATAJPA-953 - Fixed typo in reference documentation. 2016-08-20 08:30:25 +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
Oliver Gierke
c228d3e5d8 DATAJPA-941 - Avoid causing exceptions in JPA type check.
We're now using Class.isInstance(…) in favor of .cast(…) in JpaClassUtils.isOfType(…) as the latter causes exceptions to be thrown unnecessarily.
2016-08-02 12:26:34 -07:00
Oliver Gierke
2facef327e DATAJPA-882 - Prepare 1.11 M1 (Ingalls). 2016-07-27 13:51:37 +02:00
Oliver Gierke
f9a3ac6990 DATAJPA-882 - Updated changelog. 2016-07-27 13:51:27 +02: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
Thomas Darimont
b0d03050cb DATAJPA-413 - Improved handling of entities annotated with @IdClass.
Added special handling for IdClass' typed id values to prevent
nested identifier classes from failing to be populated in JpaMetamodelEntityInformation.

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
0f1e3f1dd0 DATAJPA-884 - Updated changelog. 2016-06-15 14:31:47 +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
883cb81420 DATAJPA-911 - More reflection to adapt to changes in Hibernate 5.2.
We now workaround a JPA specification violation introduced in 5.2 [0] in parameter binding. This involves removing a workaround for a bug in older Hibernate variants that returned the parameter index as String for parameters that shouldn't return a name at all. We now solve that by explicitly not considering parameter names that are purely numeric as named parameters in the first place. This also avoids producing an exception in the case of the usage of named parameters in the first place.

org.hibernate.Query was deprecated in Hibernate 5.2 but at the same time a couple of methods on it were changed in a binary incompatible way. We now explicitly detect that change in the execution of stream queries and fall back to reflection based invocation of the methods we need to call.

[0] https://hibernate.atlassian.net/browse/HHH-10803
2016-06-05 13:02:43 +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
f8450c61df DATAJPA-909 - Fixed count query execution for projections and pagination.
We now make sure that the count query for derived queries using pagination uses a plain count projection and does not try to apply that on a tuple query.
2016-06-02 12:37:36 +02:00
Michael J. Simons
f5681dd2b0 DATAJPA-908 - Added note about named parameters and @Param.
Clarifies that the use of @Param is optional when on Java 8 and compiling with -parameters flag.

Original pull request: #173.
2016-05-31 15:18:38 +02:00
Oliver Gierke
6b29fdabb6 DATAJPA-905 - Polishing.
Deprecated SimpleJpaRepository.readPage(…) and ….getCountQuery(…) variants for which we have more dedicated overloads taking the domain type already.

Some formatting polishing on the way.
2016-05-27 16:57:19 +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
9d0b487aed DATAJPA-903 - Stream access on Hibernate only unwraps first element if one element array is returned.
Previously we always picked the first element of the Object array returned by the Hibernate ScrollableResults. We now only do that for one element arrays to basically mimic the handling of List based query methods.
2016-05-25 15:03:23 +02:00
Oliver Gierke
696a3b8761 DATAJPA-891 - Polishing.
Formatting in JpaPersistentPropertyImpl.
2016-04-14 17:07:31 +02:00
Oliver Gierke
9bc6604ff3 DATAJPA-891 - Avoid creating unnecessary exceptions in JpaPersistenEntityImpl.
JpaPersistentEntityImpl.isEntity() currently called a method on the JPA meta-model, catching an exception to indicate the given type is not managed. We're now rather iterate over all managed types to avoid the overhead of the exception being thrown and handled immediately.
2016-04-14 17:07:04 +02:00
Michael J. Simons
040a010270 DATAJPA-888 - Clarify usage of native queries for pagination.
This commit changes the note of using native queries for pagination and adds an example on how to manually define a count query. Also clarify that pagination using native queries is supported, dynamic sorting not.

This adresses questions like this one http://stackoverflow.com/questions/28529584/spring-data-why-its-not-possible-to-have-paging-with-native-query/36520935#36520935.

Original pull request: #171.
2016-04-11 20:02:00 +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
c5ac2baa50 DATAJPA-881 - Updated changelog. 2016-04-06 23:14:22 +02:00
Oliver Gierke
f66d718f67 DATAJPA-878 - Prepare 1.10 GA (Hopper). 2016-04-06 16:34:45 +02:00
Oliver Gierke
1ba904b1db DATAJPA-878 - Updated changelog. 2016-04-06 16:34:33 +02:00
Christoph Strobl
b16f18a605 DATAJPA-876, DATAJPA-838 - Add AD-HOC entity graph sample and what's new section.
Original pull request: #167
2016-04-04 14:50:40 +02:00