Steve Ebersole 2016-11-16 11:00:17 -06:00
parent 4960da8471
commit 31a60b84c6
3 changed files with 128 additions and 0 deletions

View File

@ -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 );
}
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}