1

I am using Hibernate custom user type to map enum to a table varchar/char. I am using custom user type code from here (https://community.jboss.org/wiki/Java5StringValuedEnumUserType). I am trying following annotation to do the mapping but its not working.

@Transient
@Type(type = "data.model.base.StringValuedEnumType", parameters = {
        @Parameter(name = "enumClass", value = "data.common.TypeEnum"),
        @Parameter(name = "identifierMethod", value = "dbCode") })
private TypeEnum typeEnum;

TypeEnum code:

public enum TypeEnum implements StringValuedEnum {

OFF("OFF", "O"),
ON("ON, "O"),

private String dbCode;
private String desc;

TypeEnum(String desc, String dbCode) {
    this.desc=desc;
    this.dbCode = dbCode;
}

@Override
public String dbCode() {
    return dbCode;
}

public String desc() {
    return desc;
}
}

I believe I am doing something wrong in the annotation but I am not able to figure out what is it. Any idea anyone?

4

1 回答 1

2

我找到了。我通过删除@Transient 并为映射添加@Column 来更新注释。我还更新了代码以处理传递的名称并删除了 defaultValue。

@Column(name = "TYP_CD", length = 1)
@Type(type = "data.model.base.StringValuedEnumType", parameters = {
    @Parameter(name = "enumClass", value = "data.common.TypeEnum")})
private TypeEnum typeEnum;
于 2013-09-17T16:39:45.650 回答