HHH-10206 - Primary key not created for a Set after loading from XML mapping file
This commit is contained in:
parent
c07e93bfb1
commit
e71627ab00
|
@ -66,6 +66,11 @@ public class PluralAttributeElementSourceBasicImpl
|
||||||
return jaxbElement.getColumnOrFormula();
|
return jaxbElement.getColumnOrFormula();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean isNullable() {
|
||||||
|
return !jaxbElement.isNotNull();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SizeSource getSizeSource() {
|
public SizeSource getSizeSource() {
|
||||||
return Helper.interpretSizeSource(
|
return Helper.interpretSizeSource(
|
||||||
|
|
|
@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
|
*/
|
||||||
|
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)"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,8 +6,50 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.hbm.index;
|
package org.hibernate.test.hbm.index;
|
||||||
|
|
||||||
/**
|
import java.util.HashMap;
|
||||||
* @author Steve Ebersole
|
import java.util.HashSet;
|
||||||
*/
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class PersonGroup {
|
public class PersonGroup {
|
||||||
|
private long id;
|
||||||
|
private String name;
|
||||||
|
private Set<Person> persons = new HashSet<Person>();
|
||||||
|
private Map<String, String> comments = new HashMap<String,String>();
|
||||||
|
|
||||||
|
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<Person> getPersons() {
|
||||||
|
return persons;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPersons(Set<Person> persons) {
|
||||||
|
this.persons = persons;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getComments() {
|
||||||
|
return comments;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setComments(Map<String, String> comments) {
|
||||||
|
this.comments = comments;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<!--
|
||||||
|
~ 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>.
|
||||||
|
-->
|
||||||
|
<!DOCTYPE hibernate-mapping PUBLIC
|
||||||
|
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||||
|
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
||||||
|
|
||||||
|
<hibernate-mapping package="org.hibernate.test.hbm.index">
|
||||||
|
|
||||||
|
<class name="PersonGroup">
|
||||||
|
<id name="id" type="long">
|
||||||
|
<generator class="native" />
|
||||||
|
</id>
|
||||||
|
<map name="comments" table="PersonGroupComment">
|
||||||
|
<key column="group" foreign-key="comment_persongroup_fk"/>
|
||||||
|
<map-key column="locale" type="string"/>
|
||||||
|
<element column="name" type="string" />
|
||||||
|
</map>
|
||||||
|
</class>
|
||||||
|
|
||||||
|
</hibernate-mapping>
|
|
@ -0,0 +1,24 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<!--
|
||||||
|
~ 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>.
|
||||||
|
-->
|
||||||
|
<!DOCTYPE hibernate-mapping PUBLIC
|
||||||
|
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||||
|
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
||||||
|
|
||||||
|
<hibernate-mapping package="org.hibernate.test.hbm.index">
|
||||||
|
|
||||||
|
<class name="PersonGroup">
|
||||||
|
<id name="id" type="long">
|
||||||
|
<generator class="native" />
|
||||||
|
</id>
|
||||||
|
<set name="persons" table="Person">
|
||||||
|
<key column="group" foreign-key="person_persongroup_fk"/>
|
||||||
|
<element column="name" type="string" not-null="true" />
|
||||||
|
</set>
|
||||||
|
</class>
|
||||||
|
|
||||||
|
</hibernate-mapping>
|
Loading…
Reference in New Issue