inverse=true in JPA annotations

2019-01-07 20:55发布

In my application I use JPA 2.0 with Hibernate as the persistence provider. I have a one-to-many relationship between two entities (using a @JoinColumn and not @JoinTable). I wanted to know how could I specify inverse=true (as specified in hbm.xml) in JPA annotations to reverse the relationship owner.

Thank you.

2条回答
孤傲高冷的网名
2楼-- · 2019-01-07 21:10

I found an answer to this. The mappedBy attribute of @OneToMany annotation behaves the same as inverse = true in the xml file.

查看更多
再贱就再见
3楼-- · 2019-01-07 21:31

The attribute mappedBy indicates that the entity in this side is the inverse of the relationship, and the owner resides in the other entity. Other entity will be having @JoinColumn annotaion and @ManyToOne relationship. Hence I think inverse = true is same as @ManyToOne annotation.

Also inverse=”true” mean this is the relationship owner to handle the relationship.

查看更多
登录 后发表回答