-->
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: Query über Criteria auf n:m verbundene Collection
PostPosted: Thu Sep 21, 2006 5:34 am 
Newbie

Joined: Mon Aug 28, 2006 8:13 am
Posts: 6
Hi

Mapping
Code:
<class name="Task" table="TASK">
        <id name="id" column="task_id">
            <generator class="native" />
        </id>
        <property name="date" column="task_date" type="timestamp" not-null="true"/>
        <property name="taskBegin" column="task_begin" type="timestamp" not-null="true"/>
        <property name="taskEnd" column="task_end" type="timestamp" not-null="true"/>
        <property name="notes" column="task_notes" />
        <many-to-one name="taskTyp" class="TaskTyp" column="tasktyp_id" not-null="true" />
           <many-to-one name="officer" class="Worker" column="worker_id" not-null="true" />
        <bag name="workers" table="TASK_WORKERS" >
            <key column="task_id" />
            <many-to-many column="worker_id" class="Worker" />
        </bag>
        <many-to-one name="report" class="Report" column="report_id" />
    </class>

<class name="Worker" table="WORKER">
        <id name="id" column="worker_id">
            <generator class="native" />
        </id>
   <property name="sign" column="worker_sign" not-null="true" unique="true" />
        <property name="firstN" column="worker_firstname" />
        <property name="lastN" column="worker_lastname" />
    </class>


DB Methode

Code:
public ArrayList<Task> getFilteredNonReportTasks(Date start, Date end, ArrayList worker, ArrayList types){
        ArrayList tasks = new ArrayList();
        Transaction tx = null;
        session = HibernateUtil.currentSession();
        try {
            tx = session.beginTransaction();
            Criteria c = session.createCriteria(Task.class).add(Expression.between("date", start, end));
         if(types.size() > 0){
            c.add(Restrictions.in("taskTyp", types));
         }
         if(worker.size() > 0){
            //c.createCriteria("workers");
            c.add(Restrictions.in("workers", worker));
         }            
         tasks = (ArrayList) c.list();
            tx.commit();
        } catch (HibernateException he) {
            if(tx!=null) tx.rollback();
            log.error("Error getting filtered Tasks.");
            throw he;
        }
        log.info("Requesting filtered Tasks successfully.");
        return tasks;       
    }


Ich möchte alle Tasks haben die innerhalb des Datumsbereichs sind und ggf. vom angegebenen TaskTyp und ggf. in der Liste der Mitarbeiter(Worker). Mir stehen die persistenten Instanzen der Worker zur verfügung.
Ich denke zu wissen das ich dazu eine Criteria an hängen muss
Code:
c.createCriteria("workers");

aber wie dann weiter wie kann ich dann Restriction angeben die mir das erwünschte ergebnis gibt und eine List zulässt. also nicht über einzel Felder von Worker ... z.B. so
Code:
c.createCriteria("workers");
c.add(Restrictions.in("id", irgendwoHerGeholteWorkerIdList));


Oder geht es nicht anders als die Worker Id in eine extra Liste zu packen??? Oder geht es ganz anders viel einfacher???

Bin für Tipps und Bemerkungen sehr dankbar

Vielen Dank im Voraus ansi_c[/b]


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.