From 3fa669831f1767976a43692f716435ea37e4153e Mon Sep 17 00:00:00 2001 From: Brett Meyer Date: Thu, 21 Feb 2013 11:10:13 -0500 Subject: [PATCH] HHH-8021 test case --- .../annotations/embedded/EmbeddableA.java | 57 ++++++++++++++++++ .../annotations/embedded/EmbeddableB.java | 40 +++++++++++++ .../embedded/EntityWithNestedEmbeddables.java | 60 +++++++++++++++++++ ...NestedEmbeddableAttributeOverrideTest.java | 59 ++++++++++++++++++ 4 files changed, 216 insertions(+) create mode 100644 hibernate-core/src/test/java/org/hibernate/test/annotations/embedded/EmbeddableA.java create mode 100644 hibernate-core/src/test/java/org/hibernate/test/annotations/embedded/EmbeddableB.java create mode 100644 hibernate-core/src/test/java/org/hibernate/test/annotations/embedded/EntityWithNestedEmbeddables.java create mode 100644 hibernate-core/src/test/java/org/hibernate/test/annotations/embedded/NestedEmbeddableAttributeOverrideTest.java diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/embedded/EmbeddableA.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/embedded/EmbeddableA.java new file mode 100644 index 0000000000..36b7a66048 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/embedded/EmbeddableA.java @@ -0,0 +1,57 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * JBoss, Home of Professional Open Source + * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors + * as indicated by the @authors tag. All rights reserved. + * See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU Lesser General Public License, v. 2.1. + * This program is distributed in the hope that it will be useful, but WITHOUT A + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License, + * v.2.1 along with this distribution; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ +package org.hibernate.test.annotations.embedded; + +import javax.persistence.AttributeOverride; +import javax.persistence.AttributeOverrides; +import javax.persistence.Column; +import javax.persistence.Embeddable; +import javax.persistence.Embedded; + +/** + * @author Brett Meyer + */ +@Embeddable +public class EmbeddableA { + + @Embedded + @AttributeOverrides({@AttributeOverride(name = "embedAttrB" , column = @Column(table = "TableB"))}) + private EmbeddableB embedB; + + private String embedAttrA; + + public EmbeddableB getEmbedB() { + return embedB; + } + + public void setEmbedB(EmbeddableB embedB) { + this.embedB = embedB; + } + + public String getEmbedAttrA() { + return embedAttrA; + } + + public void setEmbedAttrA(String embedAttrA) { + this.embedAttrA = embedAttrA; + } + +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/embedded/EmbeddableB.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/embedded/EmbeddableB.java new file mode 100644 index 0000000000..85f0e53728 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/embedded/EmbeddableB.java @@ -0,0 +1,40 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * JBoss, Home of Professional Open Source + * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors + * as indicated by the @authors tag. All rights reserved. + * See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU Lesser General Public License, v. 2.1. + * This program is distributed in the hope that it will be useful, but WITHOUT A + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License, + * v.2.1 along with this distribution; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ +package org.hibernate.test.annotations.embedded; + +import javax.persistence.Embeddable; + +/** + * @author Brett Meyer + */ +@Embeddable +public class EmbeddableB { + + private String embedAttrB; + + public String getEmbedAttrB() { + return embedAttrB; + } + + public void setEmbedAttrB(String embedAttrB) { + this.embedAttrB = embedAttrB; + } +} \ No newline at end of file diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/embedded/EntityWithNestedEmbeddables.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/embedded/EntityWithNestedEmbeddables.java new file mode 100644 index 0000000000..e310a95d2f --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/embedded/EntityWithNestedEmbeddables.java @@ -0,0 +1,60 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * JBoss, Home of Professional Open Source + * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors + * as indicated by the @authors tag. All rights reserved. + * See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU Lesser General Public License, v. 2.1. + * This program is distributed in the hope that it will be useful, but WITHOUT A + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License, + * v.2.1 along with this distribution; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ +package org.hibernate.test.annotations.embedded; + +import javax.persistence.Embedded; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.SecondaryTable; +import javax.persistence.SecondaryTables; +import javax.persistence.Table; + +/** + * @author Brett Meyer + */ +@Entity +@Table(name="TableA") +@SecondaryTables({@SecondaryTable(name = "TableB")}) +public class EntityWithNestedEmbeddables { + @Id + @GeneratedValue + private Integer id; + + @Embedded + private EmbeddableA embedA; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public EmbeddableA getEmbedA() { + return embedA; + } + + public void setEmbedA(EmbeddableA embedA) { + this.embedA = embedA; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/embedded/NestedEmbeddableAttributeOverrideTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/embedded/NestedEmbeddableAttributeOverrideTest.java new file mode 100644 index 0000000000..569ae8ab3e --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/embedded/NestedEmbeddableAttributeOverrideTest.java @@ -0,0 +1,59 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * JBoss, Home of Professional Open Source + * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors + * as indicated by the @authors tag. All rights reserved. + * See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU Lesser General Public License, v. 2.1. + * This program is distributed in the hope that it will be useful, but WITHOUT A + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License, + * v.2.1 along with this distribution; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ +package org.hibernate.test.annotations.embedded; + +import org.hibernate.Session; +import org.hibernate.testing.FailureExpected; +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.junit.Test; + +/** + * @author Brett Meyer + */ +@FailureExpected(jiraKey="HHH-8021") +public class NestedEmbeddableAttributeOverrideTest extends BaseCoreFunctionalTestCase { + + @Test + @TestForIssue(jiraKey="HHH-8021") + public void testAttributeOverride() { + EmbeddableB embedB = new EmbeddableB(); + embedB.setEmbedAttrB( "B" ); + + EmbeddableA embedA = new EmbeddableA(); + embedA.setEmbedAttrA("A"); + embedA.setEmbedB(embedB); + + EntityWithNestedEmbeddables entity = new EntityWithNestedEmbeddables(); + entity.setEmbedA(embedA); + + Session s = openSession(); + s.beginTransaction(); + s.persist( entity ); + s.getTransaction().commit(); + s.close(); + } + + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] { EntityWithNestedEmbeddables.class }; + } +}