HHH-8153 Criteria on Enum mapping defined in hbm.xml fails.
This commit is contained in:
parent
9db5400f8f
commit
d995bb9bb9
|
@ -168,7 +168,10 @@ public class EnumType implements EnhancedUserType, DynamicParameterizedType,Logg
|
|||
enumClass.getName(),
|
||||
e.getMessage()
|
||||
);
|
||||
treatAsOrdinal();
|
||||
// Originally, this was simply treatAsOrdinal(). But, for DBs that do not implement the above, enums
|
||||
// were treated as ordinal even when the *.hbm.xml explicitly define the type sqlCode. By default,
|
||||
// this is essentially the same anyway, since sqlType is defaulted to Integer.
|
||||
resolveEnumValueMapper( sqlType );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors
|
||||
* as indicated by the @authors tag. All rights reserved.
|
||||
* See the copyright.txt in the distribution for a
|
||||
* full listing of individual contributors.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use,
|
||||
* modify, copy, or redistribute it subject to the terms and conditions
|
||||
* of the GNU Lesser General Public License, v. 2.1.
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT A
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
* You should have received a copy of the GNU Lesser General Public License,
|
||||
* v.2.1 along with this distribution; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*/
|
||||
package org.hibernate.test.enums;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Brett Meyer
|
||||
*/
|
||||
public class EnumTypeTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
protected String[] getMappings() {
|
||||
return new String[] { "enums/Person.hbm.xml" };
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-8153")
|
||||
public void hbmEnumTypeTest() {
|
||||
Session s = openSession();
|
||||
s.getTransaction().begin();
|
||||
s.persist( Person.person( Gender.MALE, HairColor.BROWN ) );
|
||||
s.persist( Person.person( Gender.MALE, HairColor.BLACK ) );
|
||||
s.persist( Person.person( Gender.FEMALE, HairColor.BROWN ) );
|
||||
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 ) )
|
||||
.list().size(), 2);
|
||||
assertEquals(s.createCriteria( Person.class )
|
||||
.add( Restrictions.eq( "gender", Gender.MALE ) )
|
||||
.add( Restrictions.eq( "hairColor", HairColor.BROWN ) )
|
||||
.list().size(), 1);
|
||||
assertEquals(s.createCriteria( Person.class )
|
||||
.add( Restrictions.eq( "gender", Gender.FEMALE ) )
|
||||
.list().size(), 2);
|
||||
assertEquals(s.createCriteria( Person.class )
|
||||
.add( Restrictions.eq( "gender", Gender.FEMALE ) )
|
||||
.add( Restrictions.eq( "hairColor", HairColor.BROWN ) )
|
||||
.list().size(), 1);
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors
|
||||
* as indicated by the @authors tag. All rights reserved.
|
||||
* See the copyright.txt in the distribution for a
|
||||
* full listing of individual contributors.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use,
|
||||
* modify, copy, or redistribute it subject to the terms and conditions
|
||||
* of the GNU Lesser General Public License, v. 2.1.
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT A
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
* You should have received a copy of the GNU Lesser General Public License,
|
||||
* v.2.1 along with this distribution; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*/
|
||||
package org.hibernate.test.enums;
|
||||
|
||||
/**
|
||||
* @author Brett Meyer
|
||||
*/
|
||||
public enum Gender {
|
||||
MALE, FEMALE;
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors
|
||||
* as indicated by the @authors tag. All rights reserved.
|
||||
* See the copyright.txt in the distribution for a
|
||||
* full listing of individual contributors.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use,
|
||||
* modify, copy, or redistribute it subject to the terms and conditions
|
||||
* of the GNU Lesser General Public License, v. 2.1.
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT A
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
* You should have received a copy of the GNU Lesser General Public License,
|
||||
* v.2.1 along with this distribution; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*/
|
||||
package org.hibernate.test.enums;
|
||||
|
||||
/**
|
||||
* @author Brett Meyer
|
||||
*/
|
||||
public enum HairColor {
|
||||
BLONDE, BROWN, BLACK;
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package org.hibernate.test.enums;
|
||||
|
||||
public class Person {
|
||||
private long id;
|
||||
|
||||
private Gender gender;
|
||||
|
||||
private HairColor hairColor;
|
||||
|
||||
public static Person person(Gender gender, HairColor hairColor) {
|
||||
Person person = new Person();
|
||||
person.setGender( gender );
|
||||
person.setHairColor( hairColor );
|
||||
return person;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Gender getGender() {
|
||||
return gender;
|
||||
}
|
||||
|
||||
public void setGender(Gender gender) {
|
||||
this.gender = gender;
|
||||
}
|
||||
|
||||
public HairColor getHairColor() {
|
||||
return hairColor;
|
||||
}
|
||||
|
||||
public void setHairColor(HairColor hairColor) {
|
||||
this.hairColor = hairColor;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE hibernate-mapping PUBLIC
|
||||
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
||||
|
||||
<hibernate-mapping>
|
||||
<class name="org.hibernate.test.enums.Person">
|
||||
<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>
|
||||
</class>
|
||||
</hibernate-mapping>
|
Loading…
Reference in New Issue