-
Notifications
You must be signed in to change notification settings - Fork 3.7k
HHH-19542 Ensure columns in embeddables default to correct table #10476
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
...test/java/org/hibernate/orm/test/records/RecordNestedEmbeddedWithASecondaryTableTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright Red Hat Inc. and Hibernate Authors | ||
*/ | ||
package org.hibernate.orm.test.records; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Embeddable; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.SecondaryTable; | ||
import jakarta.persistence.Table; | ||
import org.hibernate.AnnotationException; | ||
import org.hibernate.boot.MetadataSources; | ||
import org.hibernate.boot.registry.StandardServiceRegistry; | ||
import org.hibernate.testing.orm.junit.DomainModel; | ||
import org.hibernate.testing.orm.junit.JiraKey; | ||
import org.hibernate.testing.orm.junit.ServiceRegistryScope; | ||
import org.hibernate.testing.orm.junit.SessionFactory; | ||
import org.hibernate.testing.orm.junit.SessionFactoryScope; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.fail; | ||
|
||
@JiraKey("HHH-19542") | ||
@DomainModel(annotatedClasses = { | ||
RecordNestedEmbeddedWithASecondaryTableTest.UserEntity.class | ||
}) | ||
@SessionFactory | ||
class RecordNestedEmbeddedWithASecondaryTableTest { | ||
|
||
private UserEntity user; | ||
|
||
@BeforeAll | ||
void prepare(SessionFactoryScope scope) { | ||
scope.inTransaction( session -> { | ||
Person person = new Person( new FullName( "Sylvain", "Lecoy" ), 38 ); | ||
user = new UserEntity( person ); | ||
session.persist( user ); | ||
} ); | ||
} | ||
|
||
@Test | ||
void test(SessionFactoryScope scope) { | ||
scope.inTransaction(session -> { | ||
UserEntity entity = session.find( UserEntity.class, user.id ); | ||
assertThat( entity ).isNotNull(); | ||
assertThat( entity.id ).isEqualTo( user.id ); | ||
assertThat( entity.person ).isNotNull(); | ||
assertThat( entity.person.age ).isEqualTo( 38 ); | ||
assertThat( entity.person.fullName.firstName ).isEqualTo( "Sylvain" ); | ||
assertThat( entity.person.fullName.lastName ).isEqualTo( "Lecoy" ); | ||
}); | ||
} | ||
|
||
@Test | ||
void test(ServiceRegistryScope scope) { | ||
final StandardServiceRegistry registry = scope.getRegistry(); | ||
final MetadataSources sources = new MetadataSources( registry ).addAnnotatedClass( UserEntity1.class ); | ||
|
||
try { | ||
sources.buildMetadata(); | ||
fail( "Expecting to fail" ); | ||
} catch (AnnotationException expected) { | ||
assertThat( expected ).hasMessageContaining( "all properties of the embeddable class must map to the same table" ); | ||
} | ||
} | ||
|
||
@Entity | ||
@Table(name = "UserEntity") | ||
@SecondaryTable(name = "Person") | ||
static class UserEntity { | ||
@Id | ||
@GeneratedValue | ||
private Integer id; | ||
private Person person; | ||
|
||
public UserEntity( | ||
final Person person) { | ||
this.person = person; | ||
} | ||
|
||
protected UserEntity() { | ||
|
||
} | ||
} | ||
|
||
@Embeddable | ||
record Person( | ||
FullName fullName, | ||
@Column(table = "Person") | ||
Integer age) { | ||
|
||
} | ||
|
||
@Embeddable | ||
record FullName( | ||
@Column(table = "Person") | ||
String firstName, | ||
@Column(table = "Person") | ||
String lastName) { | ||
|
||
} | ||
|
||
@Entity | ||
@Table(name = "UserEntity") | ||
@SecondaryTable(name = "Person") | ||
public static class UserEntity1 { | ||
@Id | ||
@GeneratedValue | ||
private Integer id; | ||
private Person1 person; | ||
|
||
public UserEntity1( | ||
final Person1 person) { | ||
this.person = person; | ||
} | ||
|
||
protected UserEntity1() { | ||
|
||
} | ||
} | ||
|
||
@Embeddable | ||
public record Person1( | ||
FullName1 fullName, | ||
@Column(table = "Person") | ||
Integer age) { | ||
|
||
} | ||
|
||
@Embeddable | ||
public record FullName1( | ||
@Column(table = "Person") | ||
String firstName, | ||
String lastName) { | ||
|
||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.