diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/SimpleValue.java b/hibernate-core/src/main/java/org/hibernate/mapping/SimpleValue.java index 5cf4bc364a..a4f4d52033 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/SimpleValue.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/SimpleValue.java @@ -494,7 +494,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 ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/enumerated/EntityEnum.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/enumerated/EntityEnum.java index a7c7fce24d..dbb67a9616 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/enumerated/EntityEnum.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/enumerated/EntityEnum.java @@ -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; + } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/enumerated/EnumeratedTypeTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/enumerated/EnumeratedTypeTest.java index 6d5260d33b..0fd29d422f 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/enumerated/EnumeratedTypeTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/enumerated/EnumeratedTypeTest.java @@ -381,6 +381,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 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 };