Skip to content

Commit

Permalink
Fix a bunch of issues encountered with ORM 6
Browse files Browse the repository at this point in the history
  • Loading branch information
beikov committed Nov 9, 2024
1 parent ad184b3 commit 3894573
Show file tree
Hide file tree
Showing 19 changed files with 328 additions and 247 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ None yet

### Bug fixes

None yet
* Fix missing cascading deletes for deletes that contain joins or CTEs
* Fix some issues with PostgreSQL and Oracle multiset SQL rendering with Hibernate ORM 6+
* Fix returning clause rendering for PostgreSQL with Hibernate ORM 6+

### Backwards-incompatible changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ private void renderEquality(Expression left, Expression right, boolean negated,
rewriteToIdParam(right);
}
} else {
if (expressionToSplit == null || dbmsDialect.supportsAnsiRowValueConstructor() || !(left instanceof ParameterExpression) && !(right instanceof ParameterExpression)) {
if (expressionToSplit == null || !(left instanceof ParameterExpression) && !(right instanceof ParameterExpression)) {
left.accept(this);
sb.append(operator);
if (quantifier != PredicateQuantifier.ONE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ public void render(FunctionRenderContext context, String[] fields, String[] sele
context.addChunk(postChunk);
context.addChunk(subquery.substring(fromIndex));
} else {
int limitIndex = SqlUtils.indexOfLimit(subquery, orderByIndex);
if (limitIndex == -1) {
if (SqlUtils.indexOfLimit(subquery, orderByIndex) == -1 && SqlUtils.indexOfFetchFirst(subquery, orderByIndex) == -1) {
context.addChunk(preChunk);

StringBuilder sb = new StringBuilder(fromIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public void render(FunctionRenderContext context, String[] fields, String[] sele
context.addChunk("))");
context.addChunk(subquery.substring(fromIndex));
} else {
int limitIndex = SqlUtils.indexOfLimit(subquery, orderByIndex);
if (limitIndex == -1) {
if (SqlUtils.indexOfLimit(subquery, orderByIndex) == -1 && SqlUtils.indexOfFetchFirst(subquery, orderByIndex) == -1) {
renderJsonObjectArguments(context, fields, selectItemExpressions);
context.addChunk("))");
context.addChunk(" OVER (");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public void render(FunctionRenderContext context, String[] fields, String[] sele
context.addChunk("))");
context.addChunk(subquery.substring(fromIndex));
} else {
int limitIndex = SqlUtils.indexOfLimit(subquery, orderByIndex);
if (limitIndex == -1) {
if (SqlUtils.indexOfLimit(subquery, orderByIndex) == -1 && SqlUtils.indexOfFetchFirst(subquery, orderByIndex) == -1) {
renderXmlElementArguments(context, fields, selectItemExpressions);
context.addChunk("))");
context.addChunk(" OVER (");
Expand Down
32 changes: 31 additions & 1 deletion core/testsuite-hibernate/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<properties>
<module.name>com.blazebit.persistence.core.testsuite.hibernate</module.name>
<testBasePackage>com.blazebit.persistence.testsuite</testBasePackage>
<testBasePackage>com.blazebit.persistence.testsuite.hibernate</testBasePackage>
<surefireForkCount>0</surefireForkCount>
</properties>

Expand Down Expand Up @@ -634,5 +634,35 @@
</plugins>
</build>
</profile>
<profile>
<!-- No need to run this with the APT profile -->
<id>hibernate-apt</id>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<skip>true</skip>
<skipMain>true</skipMain>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<!-- No need to run this with EclipseLink -->
<id>eclipselink</id>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<skip>true</skip>
<skipMain>true</skipMain>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* SPDX-License-Identifier: Apache-2.0
* Copyright Blazebit
*/
package com.blazebit.persistence.testsuite.hibernate6.entity;
package com.blazebit.persistence.testsuite.hibernate.entity;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* SPDX-License-Identifier: Apache-2.0
* Copyright Blazebit
*/
package com.blazebit.persistence.testsuite.hibernate6.entity;
package com.blazebit.persistence.testsuite.hibernate.entity;

public interface Property<T> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* SPDX-License-Identifier: Apache-2.0
* Copyright Blazebit
*/
package com.blazebit.persistence.testsuite.hibernate6.entity;
package com.blazebit.persistence.testsuite.hibernate.entity;

import jakarta.persistence.Column;
import jakarta.persistence.DiscriminatorType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* SPDX-License-Identifier: Apache-2.0
* Copyright Blazebit
*/
package com.blazebit.persistence.testsuite.hibernate6.entity;
package com.blazebit.persistence.testsuite.hibernate.entity;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import com.blazebit.persistence.CriteriaBuilder;
import com.blazebit.persistence.testsuite.AbstractCoreTest;
import com.blazebit.persistence.testsuite.hibernate6.entity.PropertyHolder;
import com.blazebit.persistence.testsuite.hibernate.entity.PropertyHolder;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertTrue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ public static String writeGeneratedAnnotation(ImportContext importContext, Conte
public static void writeGeneratedAnnotation(StringBuilder generatedAnnotation, ImportContext importContext, Context context) {
generatedAnnotation.append("@");
if (importContext == null) {
generatedAnnotation.append(context.getGeneratedAnnotation().getQualifiedName().toString());
generatedAnnotation.append(context.getGeneratedAnnotation());
} else {
generatedAnnotation.append(importContext.importType(context.getGeneratedAnnotation().getQualifiedName().toString()));
generatedAnnotation.append(importContext.importType(context.getGeneratedAnnotation()));
}
generatedAnnotation.append("(value = \"")
.append(EntityViewAnnotationProcessor.class.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class Context {
private static final Object NULL_OBJECT = new Object();
private final ProcessingEnvironment pe;
private final boolean logDebug;
private final TypeElement generatedAnnotation;
private final String generatedAnnotation;

private final Map<String, MetaEntityView> metaEntityViews = new ConcurrentHashMap<>();
private final ConcurrentMap<String, Boolean> generatedModelClasses = new ConcurrentHashMap<>();
Expand Down Expand Up @@ -73,7 +73,7 @@ public Context(ProcessingEnvironment pe) {

Map<String, TypeMirror> optionalParameters = new HashMap<>();
Map<String, Map<String, TypeConverter>> converters = new HashMap<>();
generatedAnnotation = pe.getElementUtils().getTypeElement("javax.annotation.processing.Generated");
generatedAnnotation = "javax.annotation.processing.Generated";
for (TypeConverter typeConverter : ServiceLoader.load(TypeConverter.class, Context.class.getClassLoader())) {
typeConverter.addRegistrations(converters);
}
Expand Down Expand Up @@ -195,7 +195,7 @@ public boolean markGenerated(String name) {
return generatedModelClasses.putIfAbsent(name, Boolean.TRUE) == null;
}

public TypeElement getGeneratedAnnotation() {
public String getGeneratedAnnotation() {
return generatedAnnotation;
}

Expand Down
1 change: 1 addition & 0 deletions entity-view/testsuite/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,7 @@
<compilerArg>-AstrictCascadingCheck=false</compilerArg>
<compilerArg>-AdefaultVersionAttributeName=version</compilerArg>
<compilerArg>-AdefaultVersionAttributeType=java.lang.Long</compilerArg>
<compilerArg>-AaddGeneratedAnnotation=false</compilerArg>
</compilerArgs>
<annotationProcessors>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ protected AssertStatementBuilder deleteDocumentOwned(AssertStatementBuilder buil
.assertDelete().forRelation(Document.class, "peopleListBag").and()
.assertDelete().forRelation(Document.class, "peopleCollectionBag").and();
}
if (isQueryStrategy() && !simpleDelete && dbmsDialect.supportsModificationQueryInWithClause()) {
return builder;
}
if (supportsNestedEmbeddables()) {
builder
.assertDelete().forRelation(Document.class, "nameContainerMap").and()
Expand All @@ -228,7 +231,9 @@ protected AssertStatementBuilder deletePersonOwned(AssertStatementBuilder builde
.assertDelete().forRelation(Person.class, "favoriteDocuments").and()
;
}

if (isQueryStrategy() && !simpleDelete && dbmsDialect.supportsModificationQueryInWithClause()) {
return builder;
}
return builder
.assertDelete().forRelation(Person.class, "localized").and()
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder;
import com.blazebit.persistence.testsuite.base.jpa.category.NoEclipselink;
import com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate;
import com.blazebit.persistence.testsuite.entity.Document;
import com.blazebit.persistence.testsuite.entity.DocumentForSimpleOneToOne;
import com.blazebit.persistence.testsuite.entity.DocumentInfoSimple;
Expand All @@ -32,7 +33,7 @@
*/
@RunWith(Parameterized.class)
// NOTE: Hibernate has a bug when selecting inverse one-to-ones: https://hibernate.atlassian.net/browse/HHH-12885
@Category({ NoEclipselink.class})
@Category({ NoHibernate.class, NoEclipselink.class})
public class EntityViewUpdateSubviewInverseOneToOneEntityTest extends AbstractEntityViewUpdateTest<UpdatableDocumentForOneToOneView> {

private DocumentForSimpleOneToOne doc1;
Expand Down
Loading

0 comments on commit 3894573

Please sign in to comment.