HQL Hibernate INNER JOIN

Joins can only be used when there is an association between entities. Your Employee entity should not have a field named id_team, of type int, mapped to a column. It should have a ManyToOne association with the Team entity, mapped as a JoinColumn: @ManyToOne @JoinColumn(name=”ID_TEAM”) private Team team; Then, the following query will work flawlessly: … Read more

How to write a query in hibernate for count(*)

Suppose your login table is mapped by a LoginClass class, with emailid and password instance variables. Then you’ll execute something like: Query query = session.createQuery( “select count(*) from LoginClass login where login.emailid=:email and login.password=:password”); query.setString(“email”, “something”); query.setString(“password”, “password”); Long count = (Long)query.uniqueResult(); It should return in count the result you’re looking for. You just have … Read more

Is there a more efficient way of making pagination in Hibernate than executing select and count queries?

Baron Schwartz at MySQLPerformanceBlog.com authored a post about this. I wish there was a magic bullet for this problem, but there isn’t. Summary of the options he presented: On the first query, fetch and cache all the results. Don’t show all results. Don’t show the total count or the intermediate links to other pages. Show … Read more

Join without association in HQL

You have to use the cross join notation: from A as table_a , B as table_b where table_a.c = table_b.c Of course there is no way to implement outer joins in this manner, so you might have some trouble if that’s your case. For the analogous case with criteria refer to: hibernate-criteria-joining-table-without-a-mapped-association

How to limit result in @Query used in Spring Data Repository

You can provide limitations by limitstatement in your SQL. And have nativeQuery = true in @Query annotation to set JPA provider(like Hibernate) to consider this as a native SQL query. @Query(nativeQuery = true, value = “SELECT * FROM SLSNotification s WHERE s.userId = :userId ORDER BY snumber DESC LIMIT 20”) List<SLSNotification> getUserIdforManage(@Param(“userId”) String userId); Or … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)