-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: one-to-many issue
PostPosted: Mon Jul 26, 2010 10:49 pm 
Newbie

Joined: Sun Nov 01, 2009 9:24 pm
Posts: 12
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>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.