且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

用Hibernate映射数组

更新时间:2023-12-04 17:01:34

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<Integer> 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<Integer> getValues() {
        return values;
    }   
    ...