My suggestion is to keep those member variables that you have at the moment, and add the following to your class
@OneToMany
private List<ViewedProductsPerCategory> =
new ArrayList<ViewedProductsPerCategory>();
in that class you should have
@Entity
public class ViewedProductsPerCategory {
@Id
@GeneratedValue
long id;
@OneToMany
Category category;
long CatCounter;
long ProCounter;
getters and setters;
}
BUT make sure to keep the counters in cookie rather than calling database every time that user visit a product or category. After user's logged out add the numbers in cookie to the respective counters in database.
Issue: Be aware that user may delete the cookie before logging out, although it is very rare as most users do not delete their cookies while are logged in to avoid being logged out.