#1329 - Ebean 11.12.1 broken when using ScalarTypeConverter with enum

This commit is contained in:
Rob Bygrave
2018-03-05 19:19:27 +13:00
parent 130356cb3b
commit 740532da4b
5 changed files with 81 additions and 11 deletions
@@ -1,6 +1,7 @@
package org.tests.model.ddd;
import org.tests.model.ivo.Oid;
import org.tests.model.ivo.converter.AnEnumType;
import javax.persistence.Entity;
import javax.persistence.Id;
@@ -15,6 +16,8 @@ public class DExhEntity {
String exhange;
AnEnumType anEnumType;
@Version
Timestamp lastUpdated;
@@ -42,4 +45,11 @@ public class DExhEntity {
this.lastUpdated = lastUpdated;
}
public AnEnumType getAnEnumType() {
return anEnumType;
}
public void setAnEnumType(AnEnumType anEnumType) {
this.anEnumType = anEnumType;
}
}
@@ -0,0 +1,27 @@
package org.tests.model.ddd;
import io.ebean.Ebean;
import org.junit.Test;
import org.tests.model.ivo.Oid;
import org.tests.model.ivo.converter.AnEnumType;
import static org.assertj.core.api.Assertions.assertThat;
public class TestScalarTypeConverter {
@Test
public void integration() {
DExhEntity exhEntity = new DExhEntity();
exhEntity.setOid(new Oid<>(12));
exhEntity.setAnEnumType(AnEnumType.ONE);
Ebean.save(exhEntity);
int count = Ebean.find(DExhEntity.class)
.where().eq("anEnumType", AnEnumType.ONE)
.findCount();
assertThat(count).isGreaterThan(0);
}
}
@@ -0,0 +1,6 @@
package org.tests.model.ivo.converter;
public enum AnEnumType {
ONE,
TWO
}
@@ -0,0 +1,21 @@
package org.tests.model.ivo.converter;
import io.ebean.config.ScalarTypeConverter;
public class AnEnumTypeConvert implements ScalarTypeConverter<AnEnumType, String> {
@Override
public AnEnumType getNullValue() {
return null;
}
@Override
public AnEnumType wrapValue(String value) {
return AnEnumType.valueOf(value);
}
@Override
public String unwrapValue(AnEnumType beanType) {
return beanType.name();
}
}