0

I have several OneToMany relations in an entity.

@OneToMany(cascade = CascadeType.ALL, mappedBy = "url")
private List<Squrlimage> squrlimagelist;

and

@JoinColumn(name = "URL", referencedColumnName = "ID", insertable = false, updatable = false)
@ManyToOne(optional = false)
private Url url;

However, the relations doesn't load. It always gives a null value in the entity. What's wrong with the code? My other relations work fine. Thank you.

3 Answers 3

0

I think maybe you can move the @JoinColumn under the @ManyToOne, and ensure there is url record in your local database. And also check the ID is unique in the table.

2
  • can you check if you always use the annotation on field and do you specify any access method in the config file. if there is discrepancy, the annotation on field will be ignored.
    – cjcrobin
    Sep 11, 2013 at 6:46
  • I found it very weird that not only relations were not loading properly, but some fields were also returning null value. What could possibly be wrong?
    – Yangrui
    Sep 11, 2013 at 8:37
0

Try this

@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "url")
private List<Squrlimage> squrlimagelist;

@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name = "URL", insertable = false, updatable = false)
private Url url;
0

You have "insertable = false, updatable = false" why? This means the foreign key will not be inserted/updated, so when you read it back it will be null.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.