Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix assemble table alias for embedded entity with empty prefix and reference #1149

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2021 the original author or authors.
* Copyright 2019-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,6 +32,7 @@

/**
* @author Jens Schauder
* @author Daniil Razorenov
*/
public class PersistentPropertyPathExtensionUnitTests {

Expand Down Expand Up @@ -126,6 +127,7 @@ public void getTableAlias() {
softly.assertThat(extPath("secondList.third.value").getTableAlias()).isEqualTo(quoted("secondList_third"));
softly.assertThat(extPath("secondList").getTableAlias()).isEqualTo(quoted("secondList"));
softly.assertThat(extPath("second2.third").getTableAlias()).isEqualTo(quoted("secthird"));
softly.assertThat(extPath("second3.third").getTableAlias()).isEqualTo(quoted("second3third"));
});
}

Expand Down Expand Up @@ -217,6 +219,7 @@ static class DummyEntity {
@Id Long entityId;
Second second;
@Embedded(onEmpty = OnEmpty.USE_NULL, prefix = "sec") Second second2;
@Embedded(onEmpty = OnEmpty.USE_NULL) Second second3;
List<Second> secondList;
WithId withId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ private static class DummyEntity {
String test;

@Embedded(onEmpty = OnEmpty.USE_NULL, prefix = "PREFIX_") Embeddable embeddable;

@Embedded(onEmpty = OnEmpty.USE_NULL) Embeddable2 embeddable2;
}

@Data
Expand All @@ -287,6 +289,12 @@ private static class Embeddable {
String test;
}

@Data
private static class Embeddable2 {

@Column("ID") DummyEntity2 dummyEntity2;
}

@Data
private static class DummyEntity2 {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2021 the original author or authors.
* Copyright 2019-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,6 +31,7 @@
* available used in SQL generation and conversion
*
* @author Jens Schauder
* @author Daniil Razorenov
* @since 1.1
*/
public class PersistentPropertyPathExtension {
Expand Down Expand Up @@ -389,7 +390,12 @@ private SqlIdentifier assembleTableAlias() {
Assert.state(path != null, "Path is null");

RelationalPersistentProperty leafProperty = path.getRequiredLeafProperty();
String prefix = isEmbedded() ? leafProperty.getEmbeddedPrefix() : leafProperty.getName();
String prefix;
if (isEmbedded() && (leafProperty.getEmbeddedPrefix() == null || !leafProperty.getEmbeddedPrefix().isEmpty())) {
prefix = leafProperty.getEmbeddedPrefix();
} else {
prefix = leafProperty.getName();
}

if (path.getLength() == 1) {
Assert.notNull(prefix, "Prefix mus not be null.");
Expand Down