HHH-10766 Resolve mapping 'type' parameter error
(cherry picked from commit 50b7882663
)
This commit is contained in:
parent
1c4db6f1c0
commit
54d913e6ba
|
@ -156,7 +156,7 @@ public class EnumType implements EnhancedUserType, DynamicParameterizedType,Logg
|
||||||
return new OrdinalEnumValueMapper();
|
return new OrdinalEnumValueMapper();
|
||||||
}
|
}
|
||||||
else if ( isCharacterType( type ) ) {
|
else if ( isCharacterType( type ) ) {
|
||||||
return new OrdinalEnumValueMapper();
|
return new NamedEnumValueMapper();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new HibernateException(
|
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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,6 +13,8 @@ public class Person {
|
||||||
|
|
||||||
private HairColor hairColor;
|
private HairColor hairColor;
|
||||||
|
|
||||||
|
private HairColor originalHairColor;
|
||||||
|
|
||||||
public static Person person(Gender gender, HairColor hairColor) {
|
public static Person person(Gender gender, HairColor hairColor) {
|
||||||
Person person = new Person();
|
Person person = new Person();
|
||||||
person.setGender( gender );
|
person.setGender( gender );
|
||||||
|
@ -43,4 +45,12 @@ public class Person {
|
||||||
public void setHairColor(HairColor hairColor) {
|
public void setHairColor(HairColor hairColor) {
|
||||||
this.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">
|
<id name="id" type="long">
|
||||||
<generator class="native"></generator>
|
<generator class="native"></generator>
|
||||||
</id>
|
</id>
|
||||||
|
|
||||||
<property name="gender" not-null="true">
|
<property name="gender" not-null="true">
|
||||||
<type name="org.hibernate.type.EnumType">
|
<type name="org.hibernate.type.EnumType">
|
||||||
<param name="enumClass">org.hibernate.test.enums.Gender</param>
|
<param name="enumClass">org.hibernate.test.enums.Gender</param>
|
||||||
<param name="type">12</param>
|
<param name="type">12</param>
|
||||||
</type>
|
</type>
|
||||||
</property>
|
</property>
|
||||||
|
|
||||||
<property name="hairColor" not-null="true">
|
<property name="hairColor" not-null="true">
|
||||||
<type name="org.hibernate.type.EnumType">
|
<type name="org.hibernate.type.EnumType">
|
||||||
<param name="enumClass">org.hibernate.test.enums.HairColor</param>
|
<param name="enumClass">org.hibernate.test.enums.HairColor</param>
|
||||||
</type>
|
</type>
|
||||||
</property>
|
</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>
|
</class>
|
||||||
</hibernate-mapping>
|
</hibernate-mapping>
|
Loading…
Reference in New Issue