Skip to content

HHH-19542 embeddable secondary table #10340

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

Closed
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
@@ -0,0 +1,77 @@
package org.hibernate.orm.test.records;

import jakarta.persistence.*;
import org.hibernate.testing.bytecode.enhancement.EnhancementOptions;
import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.JiraKey;
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;

@JiraKey("HHH-19542")
@DomainModel(
annotatedClasses = {
RecordEmbeddableAsSecondaryTableTest.User.class
})
@SessionFactory
@BytecodeEnhanced
@EnhancementOptions(lazyLoading = true, extendedEnhancement = true, inlineDirtyChecking = true)
public class RecordEmbeddableAsSecondaryTableTest {

@BeforeAll
public void prepare(SessionFactoryScope scope) {
scope.inTransaction(session -> {
Person person = new Person(new FullName("Sylvain", "Lecoy"), 38);

User user = new User(1, person);

session.persist( user );
});
}

@Test
public void testGetEntityA(SessionFactoryScope scope) {
scope.inTransaction(session -> {
User user = session.get(User.class, 1);
assertThat( user ).isNotNull();
});
}

@Entity
@SecondaryTable(name = "Person")
public static class User {

@Id
private Integer id;

private Person person;

public User(
final Integer id,
final Person person) {
this.id = id;
this.person = person;
}

protected User() {

}
}

@Embeddable
public record Person( // If we invert, and put age as first argument, the test passes.
FullName fullName,
@Column(table = "Person")
Integer age) {
}

@Embeddable
public record FullName(
String firstName,
String lastName) {
}
}