add failing test for @ManyToOne referencing secondary table

This commit is contained in:
Gavin 2022-12-25 12:36:03 +01:00 committed by Gavin King
parent bedcc0386a
commit 1e57f88674
5 changed files with 130 additions and 0 deletions

View File

@ -0,0 +1,39 @@
package org.hibernate.orm.test.annotations.refcolnames.secondary;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.Ignore;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@Ignore
@TestForIssue(jiraKey = "HHH-15933")
@SessionFactory
@DomainModel(annotatedClasses = {Split.class, Reference.class})
public class RefToSecondaryTableTest {
@Test
public void test(SessionFactoryScope scope) {
Split split = new Split();
split.setCode(123);
split.setDescription("blah");
split.setName("Split");
Reference reference = new Reference();
reference.setSplit(split);
scope.inTransaction(session -> {
session.persist( split );
session.persist( reference );
} );
scope.inSession( session -> {
Reference ref =
session.createQuery( "from Reference left join fetch split", Reference.class )
.getSingleResult();
Assertions.assertEquals( split.getId(), ref.getSplit().getId() );
} );
scope.inSession(session -> {
Reference ref = session.find( Reference.class, reference.getId() );
Assertions.assertEquals( split.getId(), ref.getSplit().getId() );
} );
}
}

View File

@ -0,0 +1,33 @@
package org.hibernate.orm.test.annotations.refcolnames.secondary;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.SecondaryTable;
@Entity
public class Reference {
@Id
@GeneratedValue
@Column(name = "id")
private Long id;
@ManyToOne
@JoinColumn(name = "split_code", referencedColumnName = "code")
private Split split;
public Split getSplit() {
return split;
}
public void setSplit(Split split) {
this.split = split;
}
public Long getId() {
return id;
}
}

View File

@ -0,0 +1,54 @@
package org.hibernate.orm.test.annotations.refcolnames.secondary;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.SecondaryTable;
import org.hibernate.annotations.NaturalId;
@Entity
@SecondaryTable(name = "secondary_split")
public class Split {
@Id
@GeneratedValue
@Column(name = "id")
private Long id;
private String name;
@Column(table = "secondary_split")
private String description;
@NaturalId
@Column(table = "secondary_split")
private int code;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public Long getId() {
return id;
}
}

View File

@ -17,6 +17,7 @@ import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.annotations.SecondaryRow;
import org.hibernate.cfg.Configuration;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
@ -31,6 +32,7 @@ import static junit.framework.TestCase.assertTrue;
import static org.hibernate.cfg.AvailableSettings.FORMAT_SQL;
import static org.hibernate.cfg.AvailableSettings.SHOW_SQL;
@TestForIssue(jiraKey = "HHH-15932")
public class AlternativeToRepeatedTableTest extends BaseCoreFunctionalTestCase {
@Override

View File

@ -4,6 +4,7 @@ import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.annotations.DiscriminatorOptions;
import org.hibernate.cfg.Configuration;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
@ -19,6 +20,7 @@ import static junit.framework.TestCase.assertTrue;
import static org.hibernate.cfg.AvailableSettings.FORMAT_SQL;
import static org.hibernate.cfg.AvailableSettings.SHOW_SQL;
@TestForIssue(jiraKey = "HHH-14526")
public class RepeatedTableTest extends BaseCoreFunctionalTestCase {
@Override