-->
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.  [ 2 posts ] 
Author Message
 Post subject: lazy many-to-one doesn't work for Query
PostPosted: Thu Jul 08, 2010 12:20 pm 
Newbie

Joined: Tue Jul 15, 2008 12:34 pm
Posts: 5
i got this kinf of class,
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>

      <class lazy="true"    name="ortec.oea.bl.model.metiers.iso.commandes.CommandeIso" table="ISO_COM" >
     
      <id name="id" column="ISO_COM_ID" type="long" unsaved-value="0">
         <generator class="sequence">
           <param name="sequence">ISO_COM_SEQ</param>
         </generator>
      </id>
      <many-to-one name="chantier"                column="CHANTIER_ID"         />
      <many-to-one name="agence"                column="STRUCTURE_ID"         />
      <many-to-one name="commandeFournisseur"   column="COMMANDE_ID"         />
      <many-to-one name="fournisseur"             column="FOURNISSEUR_ID"      />
      <many-to-one name="site"                   column="FOU_SITE_ID"         />
     
      <property name="fournisseurNom"             column="FOURNISSEUR_NOM"          />
      <property name="siteNom"                   column="SITE_NOM"                />
      <property name="numero"                   column="COMMANDE"                />
      <property name="date"                      column="DATE_COMMANDE"             />
      <property name="solde"                      column="SOLDE"  type="yes_no"      />
     
   </class>
   
</hibernate-mapping>


when i load an object using
CommandeIso o = (CommandeIso) new DAOService().loadObject(CommandeIso.class, 19);
in deep the service use an session.load(clazz, id);
everetnig are ok because the object is proxyfied by javaassist, and the class name is like CommandeIso_$$_javassist_26.

when i use the Hibenate Query Object using
Code:
q = Tools.stringFormat("from {0} o where o.chantier.id=?",CommandeIso.class.getName());
l = new DAOService().findObjects(q, new Long(7), 0, 2);


where find object use the list method of the Query object
Code:
   public List    findObjects(String query, Object[] parameters, int firstresult, int maxresult) throws ServiceException{
      List rs=null;
      long timeStart = System.currentTimeMillis();
      try {
            Session se = HibernateListener.currentSession();
             Query q = se.createQuery(query);
             if (firstresult >=0){
                q.setFirstResult(firstresult);
             }
             if (maxresult >=0){
              q.setMaxResults(maxresult);
             }

            // positionne les paramétres
            // -------------------------
            if (parameters!=null) {
               for (int i=0; i<parameters.length;i++){                       
q.setParameter(i, parameters[i]);

                                 

               }               
            }
            rs = q.list();


Top
 Profile  
 
 Post subject: Re: lazy many-to-one doesn't work for Query
PostPosted: Thu Jul 08, 2010 12:42 pm 
Newbie

Joined: Tue Jul 15, 2008 12:34 pm
Posts: 5
oups hit the wrong button ... so after using the Query list method
load all my many-to-one association linked to the CommandeIso Object.
because i can see the SQL select done by hibernate and the objects in
the list are now of type CommandeIso

any idea?


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

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.