Adding an enum as a class property in HBM

前端 未结 6 1932
走了就别回头了
走了就别回头了 2021-01-01 16:38

I am trying to create a class in HBM file which contains an Enum as a field.

The HBM is similar to this:



        
6条回答
  •  灰色年华
    2021-01-01 17:09

    1) Easy solution: use Hibernate Annotations instead of XML-based mappings. Enum support is built-in:

    @Entity
    public class MyObject {
      @Enumerated(EnumType.STRING)
      @Column(name="EXAMPLE")
      private MyEnum myEnum;
    }
    

    2) If you can't use annotations, you can still use the EnumType they provide in XML-based mappings. You do need to have appropriate hibernate-annotations.jar in your classpath during deployment but there's no compile-time dependency:

    
      
    
    

提交回复
热议问题