Mapping array with Hibernate

后端 未结 4 825
谎友^
谎友^ 2020-11-29 09:53

Can you please help me to map this class using Hibernate?

public class MyClass{
    private Long id;
    private String name;
    private int[] values;
    .         


        
4条回答
  •  死守一世寂寞
    2020-11-29 10:11

    I have never mapped arrays to hibernate. I always use collections. So, I have slightly changed you class:

    public class MyClass{
        private Long id;
        private String name;
        private List values;
    
        @Id
        // this is only if your id is really auto generated
        @GeneratedValue(strategy=GenerationType.AUTO) 
        public Long getId() {
            return id;
        }
    
        @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY)
        public List getValues() {
            return values;
        }   
        ...
    

提交回复
热议问题