HHH-9369 Fix @Formula of enum type results in ClassCastException

(cherry picked from commit fff49977ab)
This commit is contained in:
andreas 2014-08-29 10:01:52 +02:00 committed by Gail Badner
parent 45c786c54f
commit 5d065bc263
3 changed files with 39 additions and 1 deletions

View File

@ -365,7 +365,10 @@ public class SimpleValue implements KeyValue {
try {
String[] columnsNames = new String[columns.size()];
for ( int i = 0; i < columns.size(); i++ ) {
columnsNames[i] = ( (Column) columns.get( i ) ).getName();
Selectable column = columns.get(i);
if (column instanceof Column){
columnsNames[i] = ((Column) column).getName();
}
}
final XProperty xProperty = (XProperty) typeParameters.get( DynamicParameterizedType.XPROPERTY );

View File

@ -7,6 +7,7 @@ import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import org.hibernate.annotations.Formula;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
@ -54,6 +55,10 @@ public class EntityEnum {
@Enumerated(EnumType.STRING)
private Trimmed trimmed;
@Formula("(select 'A' from dual)")
@Enumerated(EnumType.STRING)
private Trimmed formula;
public long getId() {
return id;
}
@ -109,4 +114,12 @@ public class EntityEnum {
public void setTrimmed(Trimmed trimmed) {
this.trimmed = trimmed;
}
public Trimmed getFormula() {
return formula;
}
public void setFormula(Trimmed formula) {
this.formula = formula;
}
}

View File

@ -373,6 +373,28 @@ public class EnumeratedTypeTest extends BaseCoreFunctionalTestCase {
s.close();
}
@Test
@TestForIssue(jiraKey = "HHH-9369")
public void testFormula() throws SQLException {
// use native SQL to insert, forcing whitespace to occur
final Session s = openSession();
final Connection connection = ((SessionImplementor)s).connection();
final Statement statement = connection.createStatement();
statement.execute("insert into EntityEnum (id) values(1)");
s.getTransaction().begin();
// ensure EnumType can do #fromName with the trimming
List<EntityEnum> resultList = s.createQuery("select e from EntityEnum e").list();
assertEquals( resultList.size(), 1 );
assertEquals( resultList.get(0).getFormula(), Trimmed.A );
statement.execute( "delete from EntityEnum" );
s.getTransaction().commit();
s.close();
}
@Override
protected Class[] getAnnotatedClasses() {
return new Class[] { EntityEnum.class };