diff --git a/hibernate-core/src/test/java/org/hibernate/test/mapping/joinformula/ChildEntity.java b/hibernate-core/src/test/java/org/hibernate/test/mapping/joinformula/ChildEntity.java new file mode 100644 index 0000000000..d30ae85398 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/mapping/joinformula/ChildEntity.java @@ -0,0 +1,25 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.test.mapping.joinformula; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; + +@Entity +public class ChildEntity { + + @Id + private Long id; + + @Column(name = "PARENT_ID") + private Long parentId; + + @Column + private String name; + +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/mapping/joinformula/JoinFormulaTest.java b/hibernate-core/src/test/java/org/hibernate/test/mapping/joinformula/JoinFormulaTest.java new file mode 100644 index 0000000000..343b0bc65c --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/mapping/joinformula/JoinFormulaTest.java @@ -0,0 +1,41 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.test.mapping.joinformula; + +import org.hibernate.Session; +import org.hibernate.cfg.AvailableSettings; +import org.hibernate.cfg.Configuration; + +import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.junit.Test; + +public class JoinFormulaTest extends BaseCoreFunctionalTestCase { + + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] { + ParentEntity.class, + ChildEntity.class + }; + } + + @Override + protected void configure(Configuration configuration) { + super.configure( configuration ); + configuration.setProperty( AvailableSettings.SHOW_SQL, Boolean.TRUE.toString() ); + configuration.setProperty( AvailableSettings.FORMAT_SQL, Boolean.TRUE.toString() ); + } + + @Test + public void hhh13722Test() { + try (Session s = openSession()) { + //Nothing to do: the test just needs to verify that + //this can boot. + } + } + +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/mapping/joinformula/ParentEntity.java b/hibernate-core/src/test/java/org/hibernate/test/mapping/joinformula/ParentEntity.java new file mode 100644 index 0000000000..c34776e31a --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/mapping/joinformula/ParentEntity.java @@ -0,0 +1,38 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.test.mapping.joinformula; + +import org.hibernate.annotations.JoinColumnOrFormula; +import org.hibernate.annotations.JoinColumnsOrFormulas; +import org.hibernate.annotations.JoinFormula; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToOne; + +@Entity +public class ParentEntity { + + @Id + private Long id; + + @OneToOne(targetEntity = ChildEntity.class, optional = false) + @JoinColumnsOrFormulas({ + @JoinColumnOrFormula(column = @JoinColumn(name = "ID", referencedColumnName = "PARENT_ID", insertable = false, updatable = false)), + @JoinColumnOrFormula(formula = @JoinFormula(referencedColumnName = "NAME", value = "'Tom'")) + }) + private ChildEntity tom; + + @OneToOne(targetEntity = ChildEntity.class, optional = false) + @JoinColumnsOrFormulas({ + @JoinColumnOrFormula(column = @JoinColumn(name = "ID", referencedColumnName = "PARENT_ID", insertable = false, updatable = false)), + @JoinColumnOrFormula(formula = @JoinFormula(referencedColumnName = "NAME", value = "'Ben'")) + }) + private ChildEntity ben; + +}