|
| 1 | +/* |
| 2 | + * Hibernate, Relational Persistence for Idiomatic Java |
| 3 | + * |
| 4 | + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. |
| 5 | + * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. |
| 6 | + */ |
| 7 | +package org.hibernate.test.annotations.formula; |
| 8 | + |
| 9 | +import java.util.HashSet; |
| 10 | +import java.util.Set; |
| 11 | +import javax.persistence.Column; |
| 12 | +import javax.persistence.Entity; |
| 13 | +import javax.persistence.Id; |
| 14 | +import javax.persistence.OneToMany; |
| 15 | +import javax.persistence.Table; |
| 16 | + |
| 17 | +import org.hibernate.SessionFactory; |
| 18 | +import org.hibernate.annotations.JoinColumnOrFormula; |
| 19 | +import org.hibernate.annotations.JoinColumnsOrFormulas; |
| 20 | +import org.hibernate.annotations.JoinFormula; |
| 21 | +import org.hibernate.boot.Metadata; |
| 22 | +import org.hibernate.boot.MetadataSources; |
| 23 | +import org.hibernate.boot.registry.StandardServiceRegistry; |
| 24 | +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; |
| 25 | + |
| 26 | +import org.hibernate.testing.FailureExpected; |
| 27 | +import org.hibernate.testing.TestForIssue; |
| 28 | +import org.hibernate.testing.junit4.BaseUnitTestCase; |
| 29 | +import org.junit.After; |
| 30 | +import org.junit.Before; |
| 31 | +import org.junit.Test; |
| 32 | + |
| 33 | +/** |
| 34 | + * @author Steve Ebersole |
| 35 | + */ |
| 36 | +public class JoinColumnOrFormulaTest extends BaseUnitTestCase { |
| 37 | + private StandardServiceRegistry ssr; |
| 38 | + |
| 39 | + @Before |
| 40 | + public void before() { |
| 41 | + ssr = new StandardServiceRegistryBuilder().build(); |
| 42 | + } |
| 43 | + |
| 44 | + @After |
| 45 | + public void after() { |
| 46 | + if ( ssr != null ) { |
| 47 | + StandardServiceRegistryBuilder.destroy( ssr ); |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + @Test |
| 52 | + @TestForIssue( jiraKey = "HHH-9897" ) |
| 53 | + @FailureExpected( jiraKey = "HHH-9897" ) |
| 54 | + public void testUseOfJoinColumnOrFormula() { |
| 55 | + Metadata metadata = new MetadataSources() |
| 56 | + .addAnnotatedClass( A.class ) |
| 57 | + .addAnnotatedClass( D.class ) |
| 58 | + .buildMetadata(); |
| 59 | + |
| 60 | + // Binding to the mapping model works after the simple change for HHH-9897 |
| 61 | + // But building the SessionFactory fails in the collection persister trying to |
| 62 | + // use the formula (it expects Columns too) |
| 63 | + metadata.buildSessionFactory().close(); |
| 64 | + } |
| 65 | + |
| 66 | + @Entity( name = "A" ) |
| 67 | + @Table( name = "A" ) |
| 68 | + public static class A { |
| 69 | + @Id |
| 70 | + @Column( name = "idA") |
| 71 | + public Integer id; |
| 72 | + |
| 73 | + @OneToMany |
| 74 | + @JoinColumnsOrFormulas({ |
| 75 | + @JoinColumnOrFormula(formula = @JoinFormula(value = "idA", referencedColumnName = "idA")) |
| 76 | + }) |
| 77 | + Set<D> ds = new HashSet<D>(); |
| 78 | + } |
| 79 | + |
| 80 | + @Entity( name = "D" ) |
| 81 | + @Table( name = "D" ) |
| 82 | + public static class D { |
| 83 | + @Id |
| 84 | + @Column( name = "idA") |
| 85 | + public Integer idA; |
| 86 | + } |
| 87 | +} |
0 commit comments