diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/PluralAttributeElementSourceBasicImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/PluralAttributeElementSourceBasicImpl.java index b35a355381..e8af40fca0 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/PluralAttributeElementSourceBasicImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/PluralAttributeElementSourceBasicImpl.java @@ -66,6 +66,11 @@ public class PluralAttributeElementSourceBasicImpl return jaxbElement.getColumnOrFormula(); } + @Override + public Boolean isNullable() { + return !jaxbElement.isNotNull(); + } + @Override public SizeSource getSizeSource() { return Helper.interpretSizeSource( diff --git a/hibernate-core/src/test/java/org/hibernate/test/hbm/collectionpk/CollectionPkTest.java b/hibernate-core/src/test/java/org/hibernate/test/hbm/collectionpk/CollectionPkTest.java new file mode 100644 index 0000000000..0689fb9332 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/hbm/collectionpk/CollectionPkTest.java @@ -0,0 +1,77 @@ +/* + * 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 . + */ +package org.hibernate.test.hbm.collectionpk; + +import java.util.Collections; + +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.tool.schema.spi.SchemaCreator; +import org.hibernate.tool.schema.spi.SchemaManagementTool; + +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.junit4.BaseUnitTestCase; +import org.hibernate.test.hbm.index.JournalingSchemaToolingTarget; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +/** + * @author Steve Ebersole + */ +@TestForIssue( jiraKey = "HHH-10206" ) +public class CollectionPkTest extends BaseUnitTestCase { + private StandardServiceRegistry ssr; + + @Before + public void before() { + ssr = new StandardServiceRegistryBuilder().build(); + } + + @After + public void after() { + if ( ssr != null ) { + StandardServiceRegistryBuilder.destroy( ssr ); + } + } + + @Test + public void testSet() { + verifyPkNameUsed( + "org/hibernate/test/hbm/collectionpk/person_set.hbm.xml", + "primary key (group, name)" + ); + } + + private void verifyPkNameUsed(String mappingResource, String expectedName) { + final Metadata metadata = new MetadataSources( ssr ) + .addResource( mappingResource ) + .buildMetadata(); + + final SchemaCreator schemaCreator = ssr.getService( SchemaManagementTool.class ).getSchemaCreator( Collections.emptyMap() ); + final JournalingSchemaToolingTarget target = new JournalingSchemaToolingTarget(); + schemaCreator.doCreation( metadata, false, target ); + + assertTrue( + "Expected foreign-key name [" + expectedName + "] not seen in schema creation output", + target.containedText( expectedName ) + ); + } + + @Test + public void testMap() { + verifyPkNameUsed( + "org/hibernate/test/hbm/collectionpk/person_map.hbm.xml", + "primary key (group, locale)" + ); + } + +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/hbm/index/PersonComment.java b/hibernate-core/src/test/java/org/hibernate/test/hbm/index/PersonComment.java new file mode 100644 index 0000000000..bc8c700b84 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/hbm/index/PersonComment.java @@ -0,0 +1,28 @@ +/* + * 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 . + */ +package org.hibernate.test.hbm.index; + +public class PersonComment { + private String locale; + private String value; + + public String getLocale() { + return locale; + } + + public void setLocale(String locale) { + this.locale = locale; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/hbm/index/PersonGroup.java b/hibernate-core/src/test/java/org/hibernate/test/hbm/index/PersonGroup.java index 0b2d366330..186495dde2 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/hbm/index/PersonGroup.java +++ b/hibernate-core/src/test/java/org/hibernate/test/hbm/index/PersonGroup.java @@ -6,8 +6,50 @@ */ package org.hibernate.test.hbm.index; -/** - * @author Steve Ebersole - */ +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + public class PersonGroup { + private long id; + private String name; + private Set persons = new HashSet(); + private Map comments = new HashMap(); + + public PersonGroup(String name) { + this.name = name; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Set getPersons() { + return persons; + } + + public void setPersons(Set persons) { + this.persons = persons; + } + + public Map getComments() { + return comments; + } + + public void setComments(Map comments) { + this.comments = comments; + } } diff --git a/hibernate-core/src/test/resources/org/hibernate/test/hbm/collectionpk/person_map.hbm.xml b/hibernate-core/src/test/resources/org/hibernate/test/hbm/collectionpk/person_map.hbm.xml new file mode 100644 index 0000000000..bbe5825688 --- /dev/null +++ b/hibernate-core/src/test/resources/org/hibernate/test/hbm/collectionpk/person_map.hbm.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/hibernate-core/src/test/resources/org/hibernate/test/hbm/collectionpk/person_set.hbm.xml b/hibernate-core/src/test/resources/org/hibernate/test/hbm/collectionpk/person_set.hbm.xml new file mode 100644 index 0000000000..3dde017764 --- /dev/null +++ b/hibernate-core/src/test/resources/org/hibernate/test/hbm/collectionpk/person_set.hbm.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file