hi.
i have three tables
User, TodoList, Todo
i need to select the count of todos for a certain logged user
how can i create the HQL statement
i dont want to use the for loop
i need to use the HQL to get the count
i am doing something like this
Code:
public Integer getHighTodoSize() {
UserBean user = userService.getLoggedInUser();
Query userBean = sessionFactory.getCurrentSession().createQuery("select t.todos from TodoListBean t where t.user=?");
userBean.setParameter(0, user);
List<TodoBean> us = userBean.list();
int listSize = 0;
for (Integer i = 0; i < us.size(); i++) {
if (us.get(i).getTodoPriority().contains("High")) {
listSize++;
}
}
return listSize;
}
Code:
<hibernate-mapping package="com.dynwar.todoList">
<class name="TodoListBean" table="TODOLIST" >
<id column="TODO_LIST_ID" name="todoListID">
<generator class="hilo"/>
</id>
<set cascade="all-delete-orphan" inverse="true" name="todos" lazy="false">
<key column="TODO_LIST_ID"/>
<one-to-many class="com.dynwar.todoList.TodoBean"/>
</set>
<many-to-one name="user" column="USER_ID" not-null="true"/>
</class>
</hibernate-mapping>
Code:
<hibernate-mapping package="com.dynwar.todoList">
<class name="TodoBean" table="TODO">
<id column="TODO_ID" name="todoID">
<generator class="native"/>
</id>
<many-to-one column="TODO_LIST_ID" name="todoList"/>
</class>
</hibernate-mapping>
Code:
<hibernate-mapping package="com.dynwar.user">
<class name="com.dynwar.user.UserBean" table="user">
<id column="USER_ID" name="userID">
<generator class="native"/>
</id>
<bag name="todoLists" cascade="all-delete-orphan" lazy="false" inverse="true">
<key column="USER_ID"/>
<one-to-many class="com.dynwar.todoList.TodoListBean"/>
</bag>
</class>
</hibernate-mapping>