-->
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: duplicate queries issued.
PostPosted: Thu Mar 31, 2005 3:31 pm 
Newbie

Joined: Tue Mar 01, 2005 3:20 pm
Posts: 6
Hi:
I have the following hbm.xml file, which defines the relationship between AGENCY and AGENT tables.

Code:
<hibernate-mapping package="com.fpi.domain.impl">
    <class name="AgencyImpl" table="AGENCY">
      <id name="agencyId" column="AGENCYID" unsaved-value="null" type="integer">
         <generator class="identity"/>
      </id>

       <property name="name" column="NAME" type="string"/>
       <property name="deleted" column="DELETED" type="string"/>
       <property name="sisId" column="SISID" type="string"/>

       <set name="agents" table="AGENT" order-by="FIRSTNAME" outer-join="true">
            <key column="AGENCYID"/>
            <one-to-many class="AgentImpl"/>
       </set>

    </class>
</hibernate-mapping>


I need to retrieve only agencies and agents which are not deleted. I use the following call:

Code:
      HibernateTemplate template = new HibernateTemplate(getSessionFactory());
        return (List) template.execute(new HibernateCallback()
        {
            public Object doInHibernate(Session session) throws HibernateException
            {
                return (List) session.createCriteria(AgencyImpl.class)
                                .createAlias("agents", "agent")
                                .add(Expression.eq("this.deleted", "N"))
                                .add(Expression.eq("agent.deleted", "N"))
                                .list();


The query is generated correctly, but then agents are retrieved for the second time by hibernate. I tried setting lazy="true" on agents, but in this case no agents are attached to the agency at all.

What is the right way of doing it?


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.