Mapping enum to string in hibernate

前端 未结 2 1504
暗喜
暗喜 2021-02-03 16:23

I\'ve got a Category Hibernate model:

@Entity
@Table(name = \"category\")
public class Category {

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
             


        
相关标签:
2条回答
  • 2021-02-03 17:00

    Yes, is possible. It should be:

    @Enumerated(EnumType.STRING)
    @Column(name = "category_type")
    private CategoryType categoryType;
    
    0 讨论(0)
  • 2021-02-03 17:07

    The accepted answer is not sufficient for PostgreSQL. I attach the implementation that worked for me:

    https://stackoverflow.com/a/64021041/5279996

    0 讨论(0)
提交回复
热议问题