I have got an easy web application with two persistent classes, User and Publish, both handled by Hibernate. I would like the consumer to have the ability to list the posts that they had not yet read. How do i implement this functionality using Hibernate?
Give a UserPost entity that consists of a person along with a Publish
Select p from Post p where p not in ( select up.post from UserPost up where up.user.id = :userId )
I am sure there's a far more performance friendly query than
not in however, you obtain the gist.
An alternative choice would be to add an accumulation of Posts the consumer and provide it a lazy fetch type but I am presuming that collection will probably get large and adding the association basically for that query does not appear great in my experience.
Adding another entity for that join table will prevent you from getting an immediate association in the User towards the Publish or the other way around. Once the user reads a publish, you give a record towards the UserPost table. You might embellish the entity having a date to keep once they browse the entry, or perhaps a count so that you can keep an eye on their most widely used posts or whatever.