i've got tricky thing i'm trying map enums storing static data.
it starts off enum classes declared such:
interface myinterface { string getname(); } public enum implements myinterface { first_a("first a"); private final string name; private a(string name) { this.name = name; } public string getname() { return name; } public string tostring() { return name; } } public enum b implements myinterface { first_b("first b"); private final string name; private b(string name) { this.name = name; } public string getname() { return name; } public string tostring() { return name; } }
now want use these as:
list<myinterface> elements
the problem comes in mapping collection. can persist these fine if use compositeusertype i've written writing class of enum being persisted string value come persisting @enumerated enumtype.string. in cases can declare:
@type(type="mycustomenumtype.class") @columns(columns = { @column(name = "enumvalue"), @column(name = "enumclass") }) private enum enumvalue;
in case can persist them fine, i'm uncertain if using @type on collection make items inside collection persist using custom type. should use @elementcollection on since it's such it's embeddable? or use user type class i've written targetclass of collection? i'm bit confused on how works that. want keep generic enough persist or b possibly in collection (although end being 1 type per entity persisted, either).
i'd prefer not have set entity class due being static data won't change, may have new version in future end being enum.
hibernate doesn't support out of box can write own usertype store qualified enum name, example com.package.type.enum_value. don't know if user types can used map 1 value/object more 1 database column.
there's example here of usertype store enum. example stores enum, might able use template.
Comments
Post a Comment