From 31a60b84c67ab2fa233627dda68f6e20cd22bd7f Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Wed, 16 Nov 2016 11:00:17 -0600 Subject: [PATCH] test for https://forum.hibernate.org/viewtopic.php?f=1&t=1043787&p=2490859#p2490859 (jira coming) --- .../CompositeNaturalIdMappingTest.java | 39 +++++++++++++++ .../naturalid/composite/PostalCarrier.java | 47 +++++++++++++++++++ .../test/naturalid/composite/PostalCode.java | 42 +++++++++++++++++ 3 files changed, 128 insertions(+) create mode 100644 hibernate-core/src/test/java/org/hibernate/test/naturalid/composite/CompositeNaturalIdMappingTest.java create mode 100644 hibernate-core/src/test/java/org/hibernate/test/naturalid/composite/PostalCarrier.java create mode 100644 hibernate-core/src/test/java/org/hibernate/test/naturalid/composite/PostalCode.java diff --git a/hibernate-core/src/test/java/org/hibernate/test/naturalid/composite/CompositeNaturalIdMappingTest.java b/hibernate-core/src/test/java/org/hibernate/test/naturalid/composite/CompositeNaturalIdMappingTest.java new file mode 100644 index 0000000000..fdfd996ccb --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/naturalid/composite/CompositeNaturalIdMappingTest.java @@ -0,0 +1,39 @@ +/* + * 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 http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.test.naturalid.composite; + +import org.hibernate.boot.Metadata; +import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.StandardServiceRegistry; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.boot.spi.MetadataImplementor; + +import org.hibernate.testing.FailureExpected; +import org.hibernate.testing.junit4.BaseUnitTestCase; +import org.junit.Test; + +/** + * @author Steve Ebersole + */ +public class CompositeNaturalIdMappingTest extends BaseUnitTestCase { + @Test + @FailureExpected( jiraKey = "tbd" ) + public void test() { + final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build(); + + try { + Metadata meta = new MetadataSources( ssr ) + .addAnnotatedClass( PostalCarrier.class ) + .addAnnotatedClass( PostalCode.class ) + .buildMetadata(); + ( ( MetadataImplementor) meta ).validate(); + } + finally { + StandardServiceRegistryBuilder.destroy( ssr ); + } + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/naturalid/composite/PostalCarrier.java b/hibernate-core/src/test/java/org/hibernate/test/naturalid/composite/PostalCarrier.java new file mode 100644 index 0000000000..4e9978c687 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/naturalid/composite/PostalCarrier.java @@ -0,0 +1,47 @@ +/* + * 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 http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.test.naturalid.composite; + +import javax.persistence.Embedded; +import javax.persistence.Entity; +import javax.persistence.Id; + +import org.hibernate.annotations.NaturalId; + +/** + * @author Steve Ebersole + */ +@Entity(name = "PostalCarrier") +public class PostalCarrier { + @Id + private Long id; + + @NaturalId + @Embedded + private PostalCode postalCode; + + public PostalCarrier(long id, PostalCode postalCode) { + this.id = id; + this.postalCode = postalCode; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public PostalCode getPostalCode() { + return postalCode; + } + + public void setPostalCode(PostalCode postalCode) { + this.postalCode = postalCode; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/naturalid/composite/PostalCode.java b/hibernate-core/src/test/java/org/hibernate/test/naturalid/composite/PostalCode.java new file mode 100644 index 0000000000..3b8852b8df --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/naturalid/composite/PostalCode.java @@ -0,0 +1,42 @@ +/* + * 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 http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.test.naturalid.composite; + +import javax.persistence.Embeddable; + +/** + * @author Steve Ebersole + */ +@Embeddable +public class PostalCode { + private String code; + private String country; + + public PostalCode() { + } + + public PostalCode(String code, String country) { + this.code = code; + this.country = country; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getCountry() { + return country; + } + + public void setCountry(String country) { + this.country = country; + } +}