Lukas Novicky
Lukas Novicky

Reputation: 952

@OrderColumn error :"null index column for collection"

I have an entity where I have a list:

@OneToMany(mappedBy = "wycenioneAuta", cascade = {CascadeType.DETACH, CascadeType.MERGE,
            CascadeType.PERSIST, CascadeType.REFRESH}, fetch = FetchType.EAGER)
    @OrderColumn(name = "photoId", nullable = false)
    public List<ImageInfo> getPhoto() {
        return photo;
    }

but when I add photo, database entry has null value in "photoId" and that results in error "org.hibernate.HibernateException: null index column for collection: ".

Thanks for your help

Upvotes: 2

Views: 5542

Answers (1)

Lukas Novicky
Lukas Novicky

Reputation: 952

Problem still is unsolved, but I needed to do something to push the project further, so I would like to share with you, how I escaped the problem.

I needed to have List instead of Set, so I moved annotations from getter, to field declaration, added annotation @Access(AccessType.FIELD) so my code tight now looks like this :

@OneToMany(mappedBy = "wycenioneAuta", cascade = {CascadeType.DETACH, CascadeType.MERGE,
            CascadeType.PERSIST, CascadeType.REFRESH}, fetch = FetchType.EAGER)
    @Access(AccessType.FIELD)
    private Set<ImageInfo> zdjecia = new LinkedHashSet<>();

Thanks to @Access annotation I can now make setter and getter as a List, and it looks like this:

public List<ImageInfo> getZdjecia() {
    return new LinkedList<>(zdjecia);
}

public void setZdjecia(List<ImageInfo> zdjecia) {
    this.zdjecia = new LinkedHashSet<>(zdjecia);
}

I hope this will help someone, as it helped me. It's not exactly what I wanted, but it works, so I think it counts :)

Upvotes: 4

Related Questions