#1438 - Mapping of @ElementCollection with an Enum that is otherwise not used produces error

This commit is contained in:
rob bygrave
2018-06-26 22:11:40 +12:00
parent 9cd189034c
commit 49ab17cd34
3 changed files with 112 additions and 0 deletions
@@ -0,0 +1,70 @@
package org.tests.model.elementcollection;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Version;
import java.util.LinkedHashSet;
import java.util.Set;
@Entity
public class EcEnumPerson {
enum Tags {
RED,
BLUE,
GREEN
}
@Id
long id;
String name;
@ElementCollection
Set<Tags> tags = new LinkedHashSet<>();
@Version
long version;
public EcEnumPerson(String name) {
this.name = name;
}
@Override
public String toString() {
return "person id:" + id + " name:" + name + " tags:" + tags;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Set<Tags> getTags() {
return tags;
}
public void setTags(Set<Tags> tags) {
this.tags = tags;
}
public long getVersion() {
return version;
}
public void setVersion(long version) {
this.version = version;
}
}
@@ -0,0 +1,33 @@
package org.tests.model.elementcollection;
import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class TestElementCollectionEnumSet extends BaseTestCase {
@Test
public void test() {
EcEnumPerson person = new EcEnumPerson("Enum Person");
person.getTags().add(EcEnumPerson.Tags.BLUE);
person.getTags().add(EcEnumPerson.Tags.RED);
Ebean.save(person);
EcEnumPerson one = Ebean.find(EcEnumPerson.class)
.setId(person.getId())
.fetch("tags")
.findOne();
assertThat(one.getTags()).hasSize(2);
one.getTags().add(EcEnumPerson.Tags.GREEN);
one.getTags().remove(EcEnumPerson.Tags.BLUE);
Ebean.save(one);
}
}