HHH-10766 Resolve mapping 'type' parameter error
(cherry picked from commit 50b7882663
)
This commit is contained in:
parent
68fced5950
commit
3ad5780256
|
@ -156,7 +156,7 @@ public class EnumType implements EnhancedUserType, DynamicParameterizedType,Logg
|
|||
return new OrdinalEnumValueMapper();
|
||||
}
|
||||
else if ( isCharacterType( type ) ) {
|
||||
return new OrdinalEnumValueMapper();
|
||||
return new NamedEnumValueMapper();
|
||||
}
|
||||
else {
|
||||
throw new HibernateException(
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* 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.enums;
|
||||
|
||||
import org.hibernate.Session;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Vlad Mihalcea
|
||||
*/
|
||||
public class EnumExplicitTypeTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
protected String[] getMappings() {
|
||||
return new String[] { "enums/Person.hbm.xml" };
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-10766")
|
||||
public void hbmEnumWithExplicitTypeTest() {
|
||||
Session s = openSession();
|
||||
s.getTransaction().begin();
|
||||
Person painted = Person.person( Gender.MALE, HairColor.BROWN );
|
||||
painted.setOriginalHairColor( HairColor.BLONDE );
|
||||
s.persist( painted );
|
||||
s.getTransaction().commit();
|
||||
s.clear();
|
||||
|
||||
s.getTransaction().begin();
|
||||
Number id = (Number) session.createNativeQuery(
|
||||
"select id from Person where originalHairColor = :color" )
|
||||
.setParameter( "color", HairColor.BLONDE.name() )
|
||||
.getSingleResult();
|
||||
assertEquals( 1L, id.longValue() );
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
}
|
|
@ -23,7 +23,7 @@ public class EnumTypeTest extends BaseCoreFunctionalTestCase {
|
|||
protected String[] getMappings() {
|
||||
return new String[] { "enums/Person.hbm.xml" };
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-8153")
|
||||
public void hbmEnumTypeTest() {
|
||||
|
@ -35,7 +35,7 @@ public class EnumTypeTest extends BaseCoreFunctionalTestCase {
|
|||
s.persist( Person.person( Gender.FEMALE, HairColor.BLACK ) );
|
||||
s.getTransaction().commit();
|
||||
s.clear();
|
||||
|
||||
|
||||
s.getTransaction().begin();
|
||||
assertEquals(s.createCriteria( Person.class )
|
||||
.add( Restrictions.eq( "gender", Gender.MALE ) )
|
||||
|
|
|
@ -13,6 +13,8 @@ public class Person {
|
|||
|
||||
private HairColor hairColor;
|
||||
|
||||
private HairColor originalHairColor;
|
||||
|
||||
public static Person person(Gender gender, HairColor hairColor) {
|
||||
Person person = new Person();
|
||||
person.setGender( gender );
|
||||
|
@ -43,4 +45,12 @@ public class Person {
|
|||
public void setHairColor(HairColor hairColor) {
|
||||
this.hairColor = hairColor;
|
||||
}
|
||||
|
||||
public HairColor getOriginalHairColor() {
|
||||
return originalHairColor;
|
||||
}
|
||||
|
||||
public void setOriginalHairColor(HairColor originalHairColor) {
|
||||
this.originalHairColor = originalHairColor;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,16 +14,26 @@
|
|||
<id name="id" type="long">
|
||||
<generator class="native"></generator>
|
||||
</id>
|
||||
|
||||
<property name="gender" not-null="true">
|
||||
<type name="org.hibernate.type.EnumType">
|
||||
<param name="enumClass">org.hibernate.test.enums.Gender</param>
|
||||
<param name="type">12</param>
|
||||
</type>
|
||||
</property>
|
||||
|
||||
<property name="hairColor" not-null="true">
|
||||
<type name="org.hibernate.type.EnumType">
|
||||
<param name="enumClass">org.hibernate.test.enums.HairColor</param>
|
||||
</type>
|
||||
</property>
|
||||
|
||||
<property name="originalHairColor">
|
||||
<type name="org.hibernate.type.EnumType">
|
||||
<param name="enumClass">org.hibernate.test.enums.HairColor</param>
|
||||
<param name="type">12</param>
|
||||
</type>
|
||||
</property>
|
||||
|
||||
</class>
|
||||
</hibernate-mapping>
|
Loading…
Reference in New Issue