HHH-12539 - Add test for issue
This commit is contained in:
parent
8916b16d3b
commit
0cf49496ff
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* 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.dynamicmap;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.hamcrest.core.IsNull.notNullValue;
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
@TestForIssue( jiraKey = "HHH-12539")
|
||||
public class DynamicMapTest extends BaseCoreFunctionalTestCase {
|
||||
@Override
|
||||
protected String[] getMappings() {
|
||||
return new String[] {
|
||||
"/dynamicmap/Test.hbm.xml"
|
||||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bootstrappingTest() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
Map item1 = new HashMap();
|
||||
item1.put( "name", "cup" );
|
||||
item1.put( "description", "abc" );
|
||||
Map entity1 = new HashMap();
|
||||
entity1.put( "name", "first_entity" );
|
||||
item1.put( "entity", entity1 );
|
||||
session.save( "Entity1", entity1 );
|
||||
session.save( "Item1", item1 );
|
||||
} );
|
||||
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
List result = session.createQuery( "from Item1" ).list();
|
||||
assertThat( result.size(), is( 1 ) );
|
||||
Map item1 = (Map) result.get( 0 );
|
||||
assertThat( item1.get( "name" ), is( "cup" ) );
|
||||
Object entity1 = item1.get( "entity" );
|
||||
assertThat( entity1, notNullValue() );
|
||||
assertThat( ( (Map) entity1 ).get( "name" ), is( "first_entity" ) );
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ 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>.
|
||||
-->
|
||||
<hibernate-mapping xmlns="http://www.hibernate.org/xsd/hibernate-mapping"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-mapping
|
||||
http://www.hibernate.org/xsd/hibernate-mapping/hibernate-mapping-4.0.xsd">
|
||||
|
||||
<class entity-name="ItemBase" abstract="true">
|
||||
<tuplizer entity-mode="dynamic-map" class="org.hibernate.tuple.entity.DynamicMapEntityTuplizer"/>
|
||||
<id name="id" type="uuid-binary" column="id" length="16">
|
||||
<generator class="uuid2" />
|
||||
</id>
|
||||
<property name="name" type="nstring" column="name" length="50" not-null="true" />
|
||||
<property name="description" type="nstring" column="description" length="200" />
|
||||
</class>
|
||||
|
||||
<union-subclass entity-name="Item1" table="item_1" extends="ItemBase">
|
||||
<tuplizer entity-mode="dynamic-map" class="org.hibernate.tuple.entity.DynamicMapEntityTuplizer"/>
|
||||
<property name="prop1" type="int" column="prop1" />
|
||||
<many-to-one name="entity" entity-name="Entity1" column="entity_id" fetch="select"/>
|
||||
</union-subclass>
|
||||
|
||||
<union-subclass entity-name="Item2" table="item_2" extends="ItemBase">
|
||||
<tuplizer entity-mode="dynamic-map" class="org.hibernate.tuple.entity.DynamicMapEntityTuplizer"/>
|
||||
<property name="prop2" type="nstring" column="prop2" length="100" />
|
||||
<many-to-one name="entity" entity-name="Entity2" column="entity_id" fetch="select" not-null="true" />
|
||||
</union-subclass>
|
||||
|
||||
<class entity-name="Entity1" table="entity_1">
|
||||
<tuplizer entity-mode="dynamic-map" class="org.hibernate.tuple.entity.DynamicMapEntityTuplizer"/>
|
||||
<id name="id" type="uuid-binary" column="id" length="16">
|
||||
<generator class="uuid2" />
|
||||
</id>
|
||||
<property name="name" type="nstring" column="name" length="50" not-null="true" />
|
||||
<set name="items" fetch="select" lazy="true" inverse="true">
|
||||
<key column="entity_id" not-null="true" />
|
||||
<one-to-many entity-name="Item1"/>
|
||||
</set>
|
||||
</class>
|
||||
|
||||
<class entity-name="Entity2" table="entity_2">
|
||||
<tuplizer entity-mode="dynamic-map" class="org.hibernate.tuple.entity.DynamicMapEntityTuplizer"/>
|
||||
<id name="id" type="uuid-binary" column="id" length="16">
|
||||
<generator class="uuid2" />
|
||||
</id>
|
||||
<property name="name" type="nstring" column="name" length="50" not-null="true" />
|
||||
<set name="items" fetch="select" lazy="true" inverse="true">
|
||||
<key column="entity_id" not-null="true" />
|
||||
<one-to-many entity-name="Item2"/>
|
||||
</set>
|
||||
</class>
|
||||
|
||||
</hibernate-mapping>
|
Loading…
Reference in New Issue