I am currently developing a Spring Boot application using Postgresql and Hibernate JPA. I want to calculate each book's popularity using the formula:
P = B + 0,7*C + 0,4*K
where B - books that are bought, C - books which are placed to cart, K - kept books
To store all these data I have created a Book2UserType
table in my database.
Also, I have Book
and User
tables.
And in order to join all three tables, I have table Book2User. This table holds the id of Book, User, and Book2UserType.
They are related using the OneToMany relationship.
Also, I've created the @Transient variable in my Book2User entity in order to store the value of popularity.
My Repository extends JpaRepository:
public interface Book2UserRepository extends JpaRepository<Book2User, Integer>
I cannot understand how I can retrieve the specific book's values in order to calculate using the formula above and sort them by this value.
I'll appreciate any help. Let me know if you need more information.
question from:
https://stackoverflow.com/questions/66059254/jpa-hibernate-and-postgresql 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…