So the question is pretty much in the title.
Let’s say I have some classe: User, Post, Comment and Tag.
- User has a @OneToMany List and
@OneToMany List. - Post has
@ManyToOne User, @OneToMany
List, @ManyToMany List. - Comment has @ManyToOne List,
@ManyToOne User. - Tag has @ManyToMany
List.
I’m new to Hibernate, but I find it easy then to use for example the attributes of a Tag object to get all the Post objects related to that tag, or find the author of a Post object or all the Post written by a certain User.
Is it OK ?
I’m talking more in terms of performance here. I’m also using the Play! framework. I don’t know if this changes anything.
I think some of them should be unidirectional.
For example, in real-world scenario you usually don’t need to display “all
Posts byUser“, because they should be filtered or paginatied, so you need to run queries against the database instead of retrievingPosts from theUser(because not filtering a collection at the database side in these use cases can be a real performance problem, especially if that collection is huge).Therefore having collection of
Posts inUsermakes no sense. The same is true forUser–CommentandTag–Postrelationships.