|
| 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.jpa.test.xml; |
| 8 | + |
| 9 | +import static org.assertj.core.api.Assertions.assertThat; |
| 10 | + |
| 11 | +import javax.persistence.AttributeOverride; |
| 12 | +import javax.persistence.Column; |
| 13 | +import javax.persistence.Embeddable; |
| 14 | +import javax.persistence.Embedded; |
| 15 | +import javax.persistence.Entity; |
| 16 | +import javax.persistence.GeneratedValue; |
| 17 | +import javax.persistence.Id; |
| 18 | +import javax.persistence.MappedSuperclass; |
| 19 | + |
| 20 | +import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; |
| 21 | + |
| 22 | +import org.hibernate.testing.TestForIssue; |
| 23 | +import org.hibernate.test.util.SchemaUtil; |
| 24 | +import org.junit.Test; |
| 25 | + |
| 26 | +public class XmlAndAnnotationAttributeOverrideTest extends BaseEntityManagerFunctionalTestCase { |
| 27 | + @Test |
| 28 | + @TestForIssue(jiraKey = "HHH-14827") |
| 29 | + public void testDerivedClassAttributeOverriding() { |
| 30 | + assertThat( SchemaUtil.getColumnNames( entityManagerFactory(), DerivedEntityType.class ) ) |
| 31 | + .contains( "custom_name" ) |
| 32 | + .doesNotContain( "name" ); |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + public void testEmbeddedAttributeOverriding() { |
| 37 | + assertThat( SchemaUtil.getColumnNames( entityManagerFactory(), DerivedEntityType.class ) ) |
| 38 | + .contains( "custom_embeddable_name" ) |
| 39 | + .doesNotContain( "embeddable_name" ); |
| 40 | + } |
| 41 | + |
| 42 | + @Override |
| 43 | + protected Class<?>[] getAnnotatedClasses() { |
| 44 | + return new Class[] { MappedSuperclassType.class, DerivedEntityType.class, EmbeddableType.class }; |
| 45 | + } |
| 46 | + |
| 47 | + @Override |
| 48 | + public String[] getEjb3DD() { |
| 49 | + return new String[] { |
| 50 | + // Using an empty orm.xml: the mere presence of an orm.xml used to trigger the bug, |
| 51 | + // regardless of its content. |
| 52 | + "org/hibernate/jpa/test/xml/orm-empty.xml" |
| 53 | + }; |
| 54 | + } |
| 55 | + |
| 56 | + @MappedSuperclass |
| 57 | + public static class MappedSuperclassType { |
| 58 | + |
| 59 | + private String name; |
| 60 | + |
| 61 | + public MappedSuperclassType() { |
| 62 | + } |
| 63 | + |
| 64 | + public MappedSuperclassType(String name) { |
| 65 | + this.name = name; |
| 66 | + } |
| 67 | + |
| 68 | + public String getName() { |
| 69 | + return name; |
| 70 | + } |
| 71 | + |
| 72 | + public void setName(String name) { |
| 73 | + this.name = name; |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + @Entity(name = "derivedentity") |
| 78 | + @AttributeOverride(name = "name", column = @Column(name = "custom_name")) |
| 79 | + public static class DerivedEntityType extends MappedSuperclassType { |
| 80 | + |
| 81 | + @Id |
| 82 | + @GeneratedValue |
| 83 | + private long id; |
| 84 | + |
| 85 | + @Embedded |
| 86 | + @AttributeOverride(name = "embeddableName", column = @Column(name = "custom_embeddable_name")) |
| 87 | + private EmbeddableType embedded; |
| 88 | + |
| 89 | + public DerivedEntityType() { |
| 90 | + } |
| 91 | + |
| 92 | + public DerivedEntityType(String name) { |
| 93 | + super( name ); |
| 94 | + } |
| 95 | + |
| 96 | + public long getId() { |
| 97 | + return id; |
| 98 | + } |
| 99 | + |
| 100 | + public void setId(long id) { |
| 101 | + this.id = id; |
| 102 | + } |
| 103 | + |
| 104 | + public EmbeddableType getEmbedded() { |
| 105 | + return embedded; |
| 106 | + } |
| 107 | + |
| 108 | + public void setEmbedded(EmbeddableType embedded) { |
| 109 | + this.embedded = embedded; |
| 110 | + } |
| 111 | + } |
| 112 | + |
| 113 | + @Embeddable |
| 114 | + public static class EmbeddableType { |
| 115 | + private String embeddableName; |
| 116 | + |
| 117 | + public String getEmbeddableName() { |
| 118 | + return embeddableName; |
| 119 | + } |
| 120 | + |
| 121 | + public void setEmbeddableName(String embeddableName) { |
| 122 | + this.embeddableName = embeddableName; |
| 123 | + } |
| 124 | + } |
| 125 | +} |
0 commit comments