mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-07 11:48:18 +00:00
HHH-9369 Fix @Formula of enum type results in ClassCastException
(cherry picked from commit fff49977ab990d65764704fd6617b775ca2032c3)
This commit is contained in:
parent
45c786c54f
commit
5d065bc263
@ -365,7 +365,10 @@ private void createParameterImpl() {
|
||||
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 );
|
||||
|
@ -7,6 +7,7 @@
|
||||
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 @@ enum Trimmed {
|
||||
@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 Trimmed getTrimmed() {
|
||||
public void setTrimmed(Trimmed trimmed) {
|
||||
this.trimmed = trimmed;
|
||||
}
|
||||
|
||||
public Trimmed getFormula() {
|
||||
return formula;
|
||||
}
|
||||
|
||||
public void setFormula(Trimmed formula) {
|
||||
this.formula = formula;
|
||||
}
|
||||
}
|
||||
|
@ -373,6 +373,28 @@ public void testTrimmedEnumChar() throws SQLException {
|
||||
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 };
|
||||
|
Loading…
x
Reference in New Issue
Block a user