简体   繁体   中英

Hibernate - mapping OneToOne on OrderColumn

Node entity

  @OneToMany(fetch = FetchType.EAGER, cascade = {CascadeType.DETACH, CascadeType.PERSIST, CascadeType.MERGE})
@OrderColumn(name = "POSITION")
private List<Node> children = new ArrayList<>();

Paragraph entity

@OneToOne(mappedBy = "paragraph")
private Node node;

When I try to do paragraph.getNode() I always get a null. What I am always missing?

You should use "@ManyToOne" instead of @OneToOne. Also, the "mappedBy" must be on the @OneToMany, like so:

@OneToMany(mappedBy = "node" ...)

Please refer to the JPA 2.0 documentation or the "JavaEE Tutorial" for an explanation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM