Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HHH-7780 - many envers tests are failing
(cherry picked from commit 07fc162)
- Loading branch information
Showing
5 changed files
with
207 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
hibernate-core/src/test/java/org/hibernate/test/enums/UnspecifiedEnumTypeEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
hibernate-core/src/test/java/org/hibernate/test/enums/UnspecifiedEnumTypeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ) { | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
hibernate-core/src/test/resources/org/hibernate/test/enums/mappings.hbm.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |