HHH-15622, HHH-13054, HHH-14940, HHH-15355 organize the tests
This commit is contained in:
parent
b6792bdb19
commit
25cb085f48
|
@ -0,0 +1,53 @@
|
|||
package org.hibernate.orm.test.annotations.refcolnames.misc;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.OneToOne;
|
||||
import org.hibernate.annotations.JoinColumnOrFormula;
|
||||
import org.hibernate.annotations.JoinFormula;
|
||||
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.jupiter.api.Test;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@DomainModel(annotatedClasses = {Misc0Test.EntityA.class, Misc0Test.EntityB.class})
|
||||
@SessionFactory
|
||||
@TestForIssue(jiraKey = "HHH-15355")
|
||||
public class Misc0Test {
|
||||
@Test
|
||||
public void test(SessionFactoryScope scope) {
|
||||
scope.inTransaction(s->{
|
||||
EntityA a = new EntityA();
|
||||
EntityB b = new EntityB();
|
||||
a.flag = 1;
|
||||
a.entityB = b;
|
||||
b.entityA = a;
|
||||
s.persist(a);
|
||||
s.persist(b);
|
||||
|
||||
s.createQuery("from B join entityA").getSingleResult();
|
||||
});
|
||||
}
|
||||
|
||||
@Entity(name = "A")
|
||||
public static class EntityA implements Serializable {
|
||||
@Id long entityBKey;
|
||||
@Id int flag;
|
||||
@OneToOne(mappedBy = "entityA")
|
||||
public EntityB entityB;
|
||||
}
|
||||
|
||||
@Entity(name = "B")
|
||||
public static class EntityB implements Serializable {
|
||||
@Id long entityBKey;
|
||||
@OneToOne
|
||||
|
||||
@JoinColumnOrFormula(column = @JoinColumn(name = "entityBKey", referencedColumnName = "entityBKey", insertable = false, updatable = false))
|
||||
@JoinColumnOrFormula(formula = @JoinFormula(value = "1", referencedColumnName = "flag"))
|
||||
public EntityA entityA;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package org.hibernate.orm.test.annotations.refcolnames.misc;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.OneToOne;
|
||||
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.jupiter.api.Test;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@DomainModel(annotatedClasses = {Misc1Test.EntityA.class, Misc1Test.EntityB.class})
|
||||
@SessionFactory
|
||||
@TestForIssue(jiraKey = "HHH-15355")
|
||||
public class Misc1Test {
|
||||
@Test
|
||||
public void test(SessionFactoryScope scope) {
|
||||
scope.inTransaction(s->{
|
||||
EntityA a = new EntityA();
|
||||
EntityB b = new EntityB();
|
||||
a.entityB = b;
|
||||
b.entityA = a;
|
||||
s.persist(a);
|
||||
s.persist(b);
|
||||
|
||||
s.createQuery("from B join entityA").getSingleResult();
|
||||
});
|
||||
}
|
||||
|
||||
@Entity(name = "A")
|
||||
public static class EntityA implements Serializable {
|
||||
@Id long entityBKey;
|
||||
@Id boolean flag;
|
||||
@OneToOne(mappedBy = "entityA")
|
||||
public EntityB entityB;
|
||||
}
|
||||
|
||||
@Entity(name = "B")
|
||||
public static class EntityB implements Serializable {
|
||||
@Id long entityBKey;
|
||||
@Id boolean flag;
|
||||
@OneToOne
|
||||
@JoinColumn(name = "entityBKey", referencedColumnName = "entityBKey", insertable = false, updatable = false)
|
||||
@JoinColumn(name = "flag", referencedColumnName = "flag", insertable = false, updatable = false)
|
||||
public EntityA entityA;
|
||||
}
|
||||
}
|
|
@ -5,12 +5,11 @@ import jakarta.persistence.Embeddable;
|
|||
import jakarta.persistence.EmbeddedId;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.JoinColumns;
|
||||
import jakarta.persistence.OneToOne;
|
||||
import jakarta.persistence.Table;
|
||||
import org.hibernate.annotations.Where;
|
||||
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;
|
||||
|
@ -20,56 +19,29 @@ import java.io.Serializable;
|
|||
import java.util.Objects;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@DomainModel(annotatedClasses = {MiscTest.EntityA.class, MiscTest.EntityB.class, MiscTest.A.class, MiscTest.B.class})
|
||||
@DomainModel(annotatedClasses = {Misc2Test.A.class, Misc2Test.B.class})
|
||||
@SessionFactory
|
||||
public class MiscTest {
|
||||
@TestForIssue(jiraKey = "HHH-15277")
|
||||
public class Misc2Test {
|
||||
@Test
|
||||
public void test(SessionFactoryScope scope) {
|
||||
scope.inTransaction(s->{
|
||||
EntityA a = new EntityA();
|
||||
EntityB b = new EntityB();
|
||||
a.entityB = b;
|
||||
b.entityA = a;
|
||||
s.persist(a);
|
||||
s.persist(b);
|
||||
});
|
||||
scope.inTransaction(s-> {
|
||||
String aIdOne = "boo";
|
||||
String aid = "boo";
|
||||
|
||||
A a2 = new A(aIdOne, "baa");
|
||||
A a = new A(aid, "baa");
|
||||
B b = new B("some2", "thing2");
|
||||
s.persist(a2);
|
||||
a2.b_R1 = b;
|
||||
b.a_R1 = a2;
|
||||
s.persist(a);
|
||||
a.b_R1 = b;
|
||||
b.a_R1 = a;
|
||||
s.persist(b);
|
||||
|
||||
A result = s.createQuery("SELECT a FROM A a WHERE a.id.aOne = :param", A.class)
|
||||
.setParameter("param", aIdOne).getSingleResult();
|
||||
assertEquals( result.id.aOne, aIdOne );
|
||||
.setParameter("param", aid).getSingleResult();
|
||||
assertEquals( result.id.aOne, aid );
|
||||
});
|
||||
}
|
||||
|
||||
@Entity
|
||||
public static class EntityA implements Serializable {
|
||||
@Id long entityBKey;
|
||||
@Id boolean flag;
|
||||
@OneToOne(mappedBy = "entityA")
|
||||
public EntityB entityB;
|
||||
}
|
||||
|
||||
@Entity
|
||||
public static class EntityB implements Serializable {
|
||||
@Id long entityBKey;
|
||||
@Id boolean flag;
|
||||
@OneToOne
|
||||
@JoinColumn(name = "entityBKey", referencedColumnName = "entityBKey", insertable = false, updatable = false)
|
||||
@JoinColumn(name = "flag", referencedColumnName = "flag", insertable = false, updatable = false)
|
||||
@Where(clause = "flag=1")
|
||||
public EntityA entityA;
|
||||
}
|
||||
|
||||
@Entity(name = "A")
|
||||
@Table(name = "a_table")
|
||||
public static class A {
|
||||
|
@ -90,10 +62,10 @@ public class MiscTest {
|
|||
@Embeddable
|
||||
public static class AId implements Serializable {
|
||||
|
||||
@Column(name = "a_one", nullable = false, length = 4096)
|
||||
@Column(name = "a_one", nullable = false)
|
||||
private String aOne;
|
||||
|
||||
@Column(name = "a_two", nullable = false, length = 4096)
|
||||
@Column(name = "a_two", nullable = false)
|
||||
private String aTwo;
|
||||
|
||||
private AId() {}
|
||||
|
@ -148,10 +120,10 @@ public class MiscTest {
|
|||
@Embeddable
|
||||
public static class BId implements Serializable {
|
||||
|
||||
@Column(name = "b_one", nullable = false, length = 4096)
|
||||
@Column(name = "b_one", nullable = false)
|
||||
private String bOne = new String("");
|
||||
|
||||
@Column(name = "b_two", nullable = false, length = 4096)
|
||||
@Column(name = "b_two", nullable = false)
|
||||
private String bTwo = new String("");
|
||||
|
||||
private BId() {}
|
|
@ -0,0 +1,76 @@
|
|||
package org.hibernate.orm.test.annotations.refcolnames.misc;
|
||||
|
||||
import jakarta.persistence.Basic;
|
||||
import jakarta.persistence.ConstraintMode;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.ForeignKey;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.JoinColumns;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.persistence.UniqueConstraint;
|
||||
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.jupiter.api.Test;
|
||||
|
||||
@DomainModel(annotatedClasses = {Misc3Test.A.class, Misc3Test.B.class})
|
||||
@SessionFactory
|
||||
@TestForIssue(jiraKey = "HHH-14687")
|
||||
public class Misc3Test {
|
||||
|
||||
@Test
|
||||
void test(SessionFactoryScope scope) {
|
||||
scope.inTransaction(x -> {});
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Table(name = "A")
|
||||
public static final class A {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Table(name = "B", uniqueConstraints = {@UniqueConstraint(columnNames = {"a_id", "uniqueName"})})
|
||||
public static final class B {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Basic
|
||||
private String uniqueName;
|
||||
@ManyToOne
|
||||
@JoinColumn(name="a_id", referencedColumnName="id")
|
||||
private A a;
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Table(name = "C", uniqueConstraints = {@UniqueConstraint(columnNames = {"a_id", "uniqueName"})})
|
||||
public static final class C {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Basic
|
||||
private String uniqueName;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name="a_id", referencedColumnName="id")
|
||||
private A a;
|
||||
@ManyToOne
|
||||
@JoinColumns(
|
||||
value = {
|
||||
@JoinColumn(name = "uniqueName", referencedColumnName = "uniqueName", insertable = false, updatable = false),
|
||||
@JoinColumn(name = "a_id", referencedColumnName = "a_id", insertable = false, updatable = false)
|
||||
},
|
||||
foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)
|
||||
)
|
||||
private B b;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,297 @@
|
|||
package org.hibernate.orm.test.annotations.refcolnames.misc;
|
||||
|
||||
import jakarta.persistence.Basic;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.IdClass;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.Table;
|
||||
import org.hibernate.annotations.Fetch;
|
||||
import org.hibernate.annotations.FetchMode;
|
||||
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.jupiter.api.Test;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@DomainModel(annotatedClasses = {Misc4Test.A.class, Misc4Test.B.class})
|
||||
@SessionFactory
|
||||
@TestForIssue(jiraKey = "HHH-13054")
|
||||
public class Misc4Test {
|
||||
|
||||
@Test
|
||||
void test(SessionFactoryScope scope) {
|
||||
scope.inTransaction(x -> {});
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Table(name = "A", schema = "", catalog = "")
|
||||
@IdClass(APK.class)
|
||||
public static class A {
|
||||
|
||||
private String a1;
|
||||
private String a2;
|
||||
private String a3;
|
||||
private String a4;
|
||||
private String a5;
|
||||
private String a6;
|
||||
private List<B> bObj;
|
||||
|
||||
@Id
|
||||
@Column(name = "A1", nullable = false, length = 15)
|
||||
public String getA1() {
|
||||
return a1;
|
||||
}
|
||||
|
||||
public void setA1(String a1) {
|
||||
this.a1 = a1;
|
||||
}
|
||||
|
||||
@Basic
|
||||
@Column(name = "A2", nullable = false, length = 15)
|
||||
public String getA2() {
|
||||
return a2;
|
||||
}
|
||||
|
||||
public void setA2(String a2) {
|
||||
this.a2 = a2;
|
||||
}
|
||||
|
||||
@Basic
|
||||
@Column(name = "A3", nullable = false, length = 15)
|
||||
public String getA3() {
|
||||
return a3;
|
||||
}
|
||||
|
||||
public void setA3(String a3) {
|
||||
this.a3 = a3;
|
||||
}
|
||||
|
||||
|
||||
@Id
|
||||
@Column(name = "A4", nullable = false, length = 15)
|
||||
public String getA4() {
|
||||
return a4;
|
||||
}
|
||||
|
||||
public void setA4(String a4) {
|
||||
this.a4 = a4;
|
||||
}
|
||||
|
||||
|
||||
@Id
|
||||
@Column(name = "A5", nullable = false, length = 15)
|
||||
public String getA5() {
|
||||
return a5;
|
||||
}
|
||||
|
||||
public void setA5(String a5) {
|
||||
this.a5 = a5;
|
||||
}
|
||||
|
||||
@Id
|
||||
@Column(name = "A6", nullable = false, length = 15)
|
||||
public String getA6() {
|
||||
return a6;
|
||||
}
|
||||
|
||||
public void setA6(String a6) {
|
||||
this.a6 = a6;
|
||||
}
|
||||
|
||||
@OneToMany(mappedBy = "aObj")
|
||||
public List<B> getB() {
|
||||
return bObj;
|
||||
}
|
||||
|
||||
public void setB(List<B> bObj) {
|
||||
this.bObj = bObj;
|
||||
}
|
||||
}
|
||||
|
||||
public static class APK implements Serializable {
|
||||
|
||||
private String a1;
|
||||
private String a4;
|
||||
private String a5;
|
||||
private String a6;
|
||||
|
||||
@Column(name = "A1", nullable = false, length = 15)
|
||||
@Id
|
||||
public String getA1() {
|
||||
return a1;
|
||||
}
|
||||
|
||||
public void setA1(String a1) {
|
||||
this.a1 = a1;
|
||||
}
|
||||
|
||||
@Column(name = "A4", nullable = false, length = 15)
|
||||
@Id
|
||||
public String getA4() {
|
||||
return a4;
|
||||
}
|
||||
|
||||
public void setA4(String a4) {
|
||||
this.a4 = a4;
|
||||
}
|
||||
|
||||
@Column(name = "A5", nullable = false, length = 15)
|
||||
@Id
|
||||
public String getA5() {
|
||||
return a5;
|
||||
}
|
||||
|
||||
public void setA5(String a5) {
|
||||
this.a5 = a5;
|
||||
}
|
||||
|
||||
public String getA6() {
|
||||
return a6;
|
||||
}
|
||||
|
||||
public void setA6(String a6) {
|
||||
this.a6 = a6;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
APK apk = (APK) o;
|
||||
return Objects.equals(a1, apk.a1) &&
|
||||
Objects.equals(a4, apk.a4) &&
|
||||
Objects.equals(a5, apk.a5) &&
|
||||
Objects.equals(a6, apk.a6);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(a1, a4, a5, a6);
|
||||
}
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Table(name = "B", schema = "", catalog = "")
|
||||
@IdClass(BPK.class)
|
||||
public static class B {
|
||||
|
||||
private int a1;
|
||||
private String a2;
|
||||
private String a3;
|
||||
private String b1;
|
||||
private String b2;
|
||||
private A aObj;
|
||||
|
||||
@Id
|
||||
@Column(name = "A1", nullable = false, length = 15)
|
||||
public int getA1() {
|
||||
return a1;
|
||||
}
|
||||
|
||||
public void setA1(int a1) {
|
||||
this.a1 = a1;
|
||||
}
|
||||
|
||||
@Id
|
||||
@Column(name = "A2", nullable = false, length = 15)
|
||||
public String getA2() {
|
||||
return a2;
|
||||
}
|
||||
|
||||
public void setA2(String a2) {
|
||||
this.a2 = a2;
|
||||
}
|
||||
|
||||
@Id
|
||||
@Column(name = "A3", nullable = false, length = 15)
|
||||
public String getA3() {
|
||||
return a3;
|
||||
}
|
||||
|
||||
public void setA3(String a3) {
|
||||
this.a3 = a3;
|
||||
}
|
||||
|
||||
@Basic
|
||||
@Column(name = "B1", nullable = false, length = 15)
|
||||
public String getB1() {
|
||||
return b1;
|
||||
}
|
||||
|
||||
public void setB1(String b1) {
|
||||
this.b1 = b1;
|
||||
}
|
||||
|
||||
@Basic
|
||||
@Column(name = "B2", nullable = false, length = 15)
|
||||
public String getB2() {
|
||||
return b2;
|
||||
}
|
||||
|
||||
public void setB2(String b2) {
|
||||
this.b2 = b2;
|
||||
}
|
||||
|
||||
|
||||
@ManyToOne(targetEntity = A.class)
|
||||
@Fetch(FetchMode.SELECT)
|
||||
@JoinColumn(name ="A1", referencedColumnName = "A1" , insertable = false, updatable = false)
|
||||
public A getaObj() {
|
||||
return aObj;
|
||||
}
|
||||
|
||||
public void setaObj(A aObj) {
|
||||
this.aObj = aObj;
|
||||
}
|
||||
}
|
||||
|
||||
public static class BPK implements Serializable {
|
||||
|
||||
private int a1;
|
||||
private String a2;
|
||||
private String a3;
|
||||
|
||||
@Column(name = "A1", nullable = false, length = 15)
|
||||
@Id
|
||||
public int getA1() {
|
||||
return a1;
|
||||
}
|
||||
|
||||
public void setA1(int a1) {
|
||||
this.a1 = a1;
|
||||
}
|
||||
|
||||
@Column(name = "A2", nullable = false, length = 15)
|
||||
@Id
|
||||
public String getA2() {
|
||||
return a2;
|
||||
}
|
||||
|
||||
public void setA2(String a2) {
|
||||
this.a2 = a2;
|
||||
}
|
||||
|
||||
@Column(name = "A3", nullable = false, length = 15)
|
||||
@Id
|
||||
public String getA3() {
|
||||
return a3;
|
||||
}
|
||||
|
||||
public void setA3(String a3) {
|
||||
this.a3 = a3;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue