2

我正在使用带有枚举键和实体值的 Map。但是,在 MySQL dbs 中创建时,枚举键列始终为空。谁能帮忙解释一下?

public enum Type{
    A,B,C
}

@Entity
public class Item{
....
.....
        @ManyToOne
    public Container getContainer() {
        return container;
    }

}

@Entity
public class Container {

....
....
        @OneToMany (mappedBy="container")   // bi-directional relation
    @MapKeyEnumerated(EnumType.STRING) 
    @MapKeyColumn(name="type", length = 20, nullable = true) 
    public Map<Type, Item> getItems() {
        return items;
    }
}

同样对于 MapKeyColumn 注释,我不能使用默认的nullable=false 。

非常感谢你的帮助。

4

0 回答 0