HHH-7780 - many envers tests are failing
This commit is contained in:
parent
5ef8a667ff
commit
07fc1627cd
|
@ -527,7 +527,9 @@ public class SimpleValue implements KeyValue {
|
|||
|
||||
final XProperty xProperty = (XProperty) typeParameters.get( DynamicParameterizedType.XPROPERTY );
|
||||
// todo : not sure this works for handling @MapKeyEnumerated
|
||||
final Annotation[] annotations = xProperty.getAnnotations();
|
||||
final Annotation[] annotations = xProperty == null
|
||||
? null
|
||||
: xProperty.getAnnotations();
|
||||
|
||||
typeParameters.put(
|
||||
DynamicParameterizedType.PARAMETER_TYPE,
|
||||
|
@ -540,7 +542,8 @@ public class SimpleValue implements KeyValue {
|
|||
table.getSchema(),
|
||||
table.getName(),
|
||||
Boolean.valueOf( typeParameters.getProperty( DynamicParameterizedType.IS_PRIMARY_KEY ) ),
|
||||
columnsNames )
|
||||
columnsNames
|
||||
)
|
||||
);
|
||||
}
|
||||
catch ( ClassNotFoundException cnfe ) {
|
||||
|
|
|
@ -261,12 +261,14 @@ public class EnumType implements EnhancedUserType, DynamicParameterizedType, Ser
|
|||
private void treatAsOrdinal() {
|
||||
if ( enumValueMapper == null || ! OrdinalEnumValueMapper.class.isInstance( enumValueMapper ) ) {
|
||||
enumValueMapper = new OrdinalEnumValueMapper();
|
||||
sqlType = enumValueMapper.getSqlType();
|
||||
}
|
||||
}
|
||||
|
||||
private void treatAsNamed() {
|
||||
if ( enumValueMapper == null || ! NamedEnumValueMapper.class.isInstance( enumValueMapper ) ) {
|
||||
enumValueMapper = new NamedEnumValueMapper();
|
||||
sqlType = enumValueMapper.getSqlType();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
package org.hibernate.test.enums;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
*/
|
||||
public class UnspecifiedEnumTypeEntity implements Serializable {
|
||||
public static enum E1 { X, Y }
|
||||
public static enum E2 { A, B }
|
||||
|
||||
private Long id;
|
||||
|
||||
private E1 enum1;
|
||||
|
||||
private E2 enum2;
|
||||
|
||||
public UnspecifiedEnumTypeEntity() {
|
||||
}
|
||||
|
||||
public UnspecifiedEnumTypeEntity(E1 enum1, E2 enum2) {
|
||||
this.enum1 = enum1;
|
||||
this.enum2 = enum2;
|
||||
}
|
||||
|
||||
public UnspecifiedEnumTypeEntity(E1 enum1, E2 enum2, Long id) {
|
||||
this.enum1 = enum1;
|
||||
this.enum2 = enum2;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if ( this == o ) return true;
|
||||
if ( ! ( o instanceof UnspecifiedEnumTypeEntity ) ) return false;
|
||||
|
||||
UnspecifiedEnumTypeEntity that = (UnspecifiedEnumTypeEntity) o;
|
||||
|
||||
if ( enum1 != that.enum1 ) return false;
|
||||
if ( enum2 != that.enum2 ) return false;
|
||||
if ( id != null ? !id.equals( that.id ) : that.id != null ) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = id != null ? id.hashCode() : 0;
|
||||
result = 31 * result + ( enum1 != null ? enum1.hashCode() : 0 );
|
||||
result = 31 * result + ( enum2 != null ? enum2.hashCode() : 0 );
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UnspecifiedEnumTypeEntity(id = " + id + ", enum1 = " + enum1 + ", enum2 = " + enum2 + ")";
|
||||
}
|
||||
|
||||
public E1 getEnum1() {
|
||||
return enum1;
|
||||
}
|
||||
|
||||
public void setEnum1(E1 enum1) {
|
||||
this.enum1 = enum1;
|
||||
}
|
||||
|
||||
public E2 getEnum2() {
|
||||
return enum2;
|
||||
}
|
||||
|
||||
public void setEnum2(E2 enum2) {
|
||||
this.enum2 = enum2;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2012, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* 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, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY 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
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.test.enums;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
/**
|
||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
*/
|
||||
@TestForIssue( jiraKey = "HHH-7780" )
|
||||
@RequiresDialect( value = H2Dialect.class )
|
||||
public class UnspecifiedEnumTypeTest extends BaseCoreFunctionalTestCase {
|
||||
@Override
|
||||
protected String[] getMappings() {
|
||||
return new String[] { "enums/mappings.hbm.xml" };
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration configuration) {
|
||||
super.configure( configuration );
|
||||
configuration.setProperty( Environment.HBM2DDL_AUTO, "" );
|
||||
}
|
||||
|
||||
@Before
|
||||
public void prepareTable() {
|
||||
Session session = openSession();
|
||||
dropTable( session );
|
||||
createTable( session );
|
||||
session.close();
|
||||
}
|
||||
|
||||
public void dropTable(Session session) {
|
||||
executeUpdateSafety( session, "drop table ENUM_ENTITY if exists" );
|
||||
}
|
||||
|
||||
private void createTable(Session session) {
|
||||
executeUpdateSafety(
|
||||
session,
|
||||
"create table ENUM_ENTITY (ID bigint not null, enum1 varchar(255), enum2 integer, primary key (ID))"
|
||||
);
|
||||
}
|
||||
|
||||
@After
|
||||
public void dropTable() {
|
||||
dropTable( session );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnumTypeDiscovery() {
|
||||
Session session = openSession();
|
||||
session.beginTransaction();
|
||||
UnspecifiedEnumTypeEntity entity = new UnspecifiedEnumTypeEntity( UnspecifiedEnumTypeEntity.E1.X, UnspecifiedEnumTypeEntity.E2.A );
|
||||
session.persist( entity );
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
private void executeUpdateSafety(Session session, String query) {
|
||||
try {
|
||||
session.createSQLQuery( query ).executeUpdate();
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="WINDOWS-1251"?>
|
||||
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
||||
<hibernate-mapping>
|
||||
<class name="org.hibernate.test.enums.UnspecifiedEnumTypeEntity" table="ENUM_ENTITY">
|
||||
<id name="id" column="ID" type="long">
|
||||
<generator class="increment" />
|
||||
</id>
|
||||
<property name="enum1">
|
||||
<type name="org.hibernate.type.EnumType">
|
||||
<!--<param name="useNamed">true</param>-->
|
||||
<param name="enumClass">org.hibernate.test.enums.UnspecifiedEnumTypeEntity$E1</param>
|
||||
</type>
|
||||
</property>
|
||||
<property name="enum2">
|
||||
<type name="org.hibernate.type.EnumType">
|
||||
<!--<param name="useNamed">false</param>-->
|
||||
<param name="enumClass">org.hibernate.test.enums.UnspecifiedEnumTypeEntity$E2</param>
|
||||
</type>
|
||||
</property>
|
||||
</class>
|
||||
</hibernate-mapping>
|
Loading…
Reference in New Issue